PHP - windows下編譯PHP 7.2的memcache

概述

PHP 7.2出來有一段時間了,不出意料,memcache又不能用了,因而又想到要本身動手編譯,不過與我編譯PHP 7.1的memcache的時候相比,有個好消息是已經有人把PHP 7.1和7.2 的memcache都編譯好並放在github上了,須要的可直接去那裏下載,我這篇文章就不提供下載了:
https://github.com/nono303/PHP7-memcache-dllphp

注:這裏仍是要強烈吐槽一下百度,以「php 7.2 memcache」爲關鍵字,徹底搜索不到任何有用的東西,上面那個網址我是用google一會兒就搜到了,並且還受到啓發,順利的把編譯過程給搞定,因此搞開發的遇到技術問題,仍是不要在百度上浪費生命了。git

我下面仍是把我研究出來的PHP 7.2 memcache的編譯方法寫出來,給有須要的人作個參考吧。github

PHP 7.2的memcache編譯方法跟以前版本有了一些變化,主要體如今:web

  1. PHP SDK的下載路徑與編譯方式發生了改變;
  2. PHP 7.2的memcache要使用VC15編譯;

下載文件

編譯前須要下載以下文件:apache

  1. 編譯環境:
    PHP-memcached是用VC15編譯的,由於並不經常使用VC15,因此到微軟的官網上下載visual studio 2017 entrpise的試用版便可。
    地址:
    https://www.visualstudio.com/zh-hans/?rr=https%3A%2F%2Fwww.microsoft.com%2Fzh-cn%2F
  2. PHP源代碼:
    從PHP官網上下載源代碼,地址:
    http://windows.php.net/downloads/releases/php-7.2.0-src.zip
  3. 下載PHP-SDK文件:
    原來的網址裏,已經沒有PHP 7.2的SDK包下載,根據其頁面上的Readme.txt的說明,要到以下地址去下載:
    https://github.com/Microsoft/php-sdk-binary-tools
  4. 下載memcache擴展包的源碼,這個地址也換了,以下:
    https://github.com/websupport-sk/pecl-memcache/tree/NON_BLOCKING_IO_php7

準備PHP代碼

注意:編譯前需先安裝好vs2017。windows

  1. 新建一個編譯目錄,如PHP72Compile;
  2. 將從https://github.com/Microsoft/php-sdk-binary-tools 下載的包解壓到這個目錄,目錄結構以下:
    PHP - windows下編譯PHP 7.2的memcache
  3. 打開cmd窗口,進入到PHP72Compile目錄;
  4. 執行phpsdk-vc15-x64.bat,結果以下圖:
    PHP - windows下編譯PHP 7.2的memcache
  5. 再運行:phpsdk_buildtree phpdev,結果以下圖:
    PHP - windows下編譯PHP 7.2的memcache
  6. 在此路徑下創建php-src目錄,並將下載的PHP源碼拷貝到這個目錄,最終目錄結構以下:
    PHP - windows下編譯PHP 7.2的memcache
  7. 在命令行進入到php-src目錄,結果以下圖:
    PHP - windows下編譯PHP 7.2的memcache
  8. 執行命令:phpsdk_deps --update --branch master,用來獲取SDK的依賴包,輸出信息以下:
D:\PHP72Compile\phpdev\vc15\x64\php-src
$ phpsdk_deps --update --branch master

Configuration: master-vc15-x64-staging

Processing package ICU-60.1-1-vc15-x64.zip
Processing package apache-2.4.28-vc15-x64.zip
Processing package c-client-2007f-vc15-x64.zip
Processing package fbclient-3.0-nocrt-x64.zip
Processing package freetype-2.8.0-1-vc15-x64.zip
Processing package glib-2.53.3-vc15-x64.zip
Processing package libargon2-20161029-vc15-x64.zip
Processing package libbzip2-1.0.6-vc15-x64.zip
Processing package libcurl-7.56.0-2-vc15-x64.zip
Processing package libenchant-1.6.0-vc15-x64.zip
Processing package libffi-3.2.1-vc15-x64.zip
Processing package libiconv-1.15-1-vc15-x64.zip
Processing package libintl-0.18.3-1-vc15-x64.zip
Processing package libjpeg-9b-vc15-x64.zip
Processing package liblmdb-0.9.21-vc15-x64.zip
Processing package libpng-1.6.34-vc15-x64.zip
Processing package libpq-9.6.5-vc15-x64.zip
Processing package libqdbm-1.8.78-vc15-x64.zip
Processing package libsasl-2.1.27-vc15-x64.zip
Processing package libssh2-1.8.0-vc15-x64.zip
Processing package libtidy-5.4.0-vc15-x64.zip
Processing package libwebp-0.6.0-vc15-x64.zip
Processing package libxml2-2.9.5-vc15-x64.zip
Processing package libxpm-3.5.12-1-vc15-x64.zip
Processing package libxslt-1.1.30-vc15-x64.zip
Processing package libzip-1.3.0-v15-x64.zip
Processing package mpir-3.0.0-vc15-x64.zip
Processing package net-snmp-5.7.3-vc15-x64.zip
Processing package nghttp2-1.24.0-vc15-x64.zip
Processing package openldap-2.4.45-vc15-x64.zip
Processing package openssl-1.1.0g-vc15-x64.zip
Processing package wineditline-2.202-vc15-x64.zip
Processing package zlib-1.2.11-vc15-x64.zip
Processing package libsodium-1.0.15-vc15-x64.zip
Updates performed successfully.
Old dependencies backed up into 'D:\PHP72Compile\phpdev\vc15\x64\deps.201712260650'.

D:\PHP72Compile\phpdev\vc15\x64\php-src
$

準備PHP memcache代碼

  1. 在與php-src同級的目錄下創建pecl\memcache目錄,並將下載的php-memcache代碼放到這個目錄下,效果以下圖:
    PHP - windows下編譯PHP 7.2的memcache
  2. 執行buildconf命令,效果以下圖:
    PHP - windows下編譯PHP 7.2的memcache
  3. 執行命令:
configure --disable-all --enable-cli --enable-zlib --enable-hash --enable-session --without-gd --with-bz2 --enable-memcache=shared --enable-fd-setsize=2048 --enable-sanitizer

輸出信息以下:api

D:\PHP72Compile\phpdev\vc15\x64\php-src
$ configure --disable-all --enable-cli --enable-zlib --enable-hash --enable-session --without-gd --with-bz2 --enable-memcache=shared --enable-fd-setsize=2048 --enable-sanitizer
PHP Version: 7.2.0

Saving configure options to config.nice.bat
Checking for cl.exe ...  <in default path>
WARNING: Using unknown MSVC version 19.12.25831

  Detected compiler MSVC 19.12.25831, untested
  Detected 64-bit compiler
Checking for link.exe ...  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\bin\HostX64\x64
Checking for nmake.exe ...  <in default path>
Checking for lib.exe ...  <in default path>
Checking for bison.exe ...  <in default path>
Checking for sed.exe ...  <in default path>
Checking for re2c.exe ...  <in default path>
  Detected re2c version 1.0.2
Checking for zip.exe ...  <in default path>
Checking for lemon.exe ...  <in default path>
Checking for mc.exe ...  C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x64
Checking for mt.exe ...  C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x64
Enabling multi process build

Build dir: D:\PHP72Compile\phpdev\vc15\x64\php-src\x64\Release_TS
PHP Core:  php7ts.dll and php7ts.lib

Checking for wspiapi.h ...  <in default path>
Enabling IPv6 support
Enabling SAPI sapi\cli
Checking for library edit_a.lib;edit.lib ... ..\deps\lib\edit_a.lib
Checking for editline/readline.h ...  D:\PHP72Compile\phpdev\vc15\x64\deps\include
Checking for library libbz2_a.lib;libbz2.lib ... ..\deps\lib\libbz2_a.lib
Checking for bzlib.h ...  D:\PHP72Compile\phpdev\vc15\x64\deps\include
Enabling extension ext\bz2
Enabling extension ext\date
Checking for KeccakHash.h ...  ext/hash/sha3/generic64lc
Enabling extension ext\hash
Enabling extension ext\pcre
Enabling extension ext\reflection
Enabling extension ext\session
Enabling extension ext\spl
Checking for timelib_config.h ...  ext/date/lib
Enabling extension ext\standard
Checking for library zlib_a.lib;zlib.lib ... ..\deps\lib\zlib_a.lib
Checking for zlib.h ...  D:\PHP72Compile\phpdev\vc15\x64\deps\include
Enabling extension ext\zlib
Enabling extension ..\pecl\memcache\php7 [shared]

Creating build dirs...
Generating files...
Generating Makefile
Generating main/internal_functions.c
Generating main/config.w32.h
Generating phpize
Done.

Enabled extensions:
-----------------------
| Extension  | Mode   |
-----------------------
| bz2        | static |
| date       | static |
| hash       | static |
| memcache   | shared |
| pcre       | static |
| reflection | static |
| session    | static |
| spl        | static |
| standard   | static |
| zlib       | static |
-----------------------

Enabled SAPI:
-------------
| Sapi Name |
-------------
| cli       |
-------------

------------------------------------------------
|                 |                            |
------------------------------------------------
| Build type      | Release                    |
| Thread Safety   | Yes                        |
| Compiler        | MSVC 19.12.25831, untested |
| Architecture    | x64                        |
| Optimization    | PGO disabled               |
| Static analyzer | disabled                   |
------------------------------------------------

Type 'nmake' to build PHP

D:\PHP72Compile\phpdev\vc15\x64\php-src
$

編譯與查看

  1. 執行nmake開始編譯,,等待幾分鐘或十幾分鍾,中間會報若干警告,不用理會;
  2. 編譯完成後,在「D:\PHP72Compile\phpdev\vc15\x64\php-src\x64\Release_TS\」目錄下可找到php_memcache.dll。
相關文章
相關標籤/搜索