PHP 7出來后,http://pecl.php.net/package/memcache上沒有for PHP7的PHP-memcache版本,需要自己編譯一個。網(wǎng)上找到的大多是在linux下的,而我需要的是windows下的版本,找了好久沒也沒有找到合適的版本,只好自己動手了。
創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比杭錦后網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式杭錦后網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋杭錦后地區(qū)。費用合理售后完善,十多年實體公司更值得信賴。
注:本文講的是編譯PHP-memcache,而不是memcached。
編譯前需要子下載如下文件:
1、 編譯環(huán)境:
PHP 7是用VC14編譯的,因此編譯PHP-memcached也需要使用VC14,因為并不常用VC14,所以到微軟的官網(wǎng)上下載visual studio 2015 entrpise的試用版即可。
2、 PHP源代碼:
從PHP官網(wǎng)上下載源代碼,地址:http://windows.php.net/downloads/releases/php-7.0.6-src.zip
3、 下載PHP-SDK文件:
地址:http://windows.php.net/downloads/php-sdk/
在這里要下載兩個文件:
4、 下載memcache擴展包的源碼:
地址:https://github.com/websupport-sk/pecl-memcache
PHP memcache官網(wǎng)已經(jīng)N年沒有更新了,上面這個網(wǎng)址是github上的支持PHP 7的分支代碼。
1、 創(chuàng)建一個用于編譯的目錄:D:\PHPCompile;
2、 解壓php-sdk-binary-tools-20110915.zip里面的文件到PHPCompile目錄下;
3、 編輯“D:\PHPCompile\bin\phpsdk_buildtree.bat”,在“GOTO EXIT”前增加代碼:
MD %_%\vc14\x86\deps\bin
MD %_%\vc14\x86\deps\lib
MD %_%\vc14\x86\deps\include
MD %_%\vc14\x64\deps\bin
MD %_%\vc14\x64\deps\lib
MD %_%\vc14\x64\deps\include
注:這是因為phpsdk_buildtree.bat年代久遠(yuǎn),還不支持VC14,因此需要進行如此修改。
4、 在開始菜單找到并打開“VS2015 x64 本機工具命令提示符”(注:如果要編譯32位的,則需進入VS2015 x86 本機工具命令提示符),進入到D:\PHPCompile目錄下,然后執(zhí)行如下命令:
bin\phpsdk_setvars.bat
bin\phpsdk_buildtree.bat phpdev
5、 執(zhí)行后,目錄下會生成phpdev文件夾;
6、 進入D:\PHPCompile\phpdev\vc14\x64\,把deps-7.0-vc14-x64.7z解壓到該目錄下,覆蓋deps文件夾
7、 把php源代碼也解壓到x64目錄下,將解壓后的目錄名改為PHP7;
8、 在x64目錄下創(chuàng)建pecl文件夾,在該文件夾下再建立memcache文件夾,將下載的PHP7-memcache代碼解壓到這個目錄下,最終的目錄結(jié)構(gòu)如下:
9、 執(zhí)行以下命令,用于創(chuàng)建php編譯配置:
cd phpdev\vc14\x64\php7
buildconf
configure --help >..\configure_help.txt
configure --disable-all --enable-cli --enable-zlib --enable-hash --enable-session --without-gd --with-bz2 --enable-memcache=shared --enable-object-out-dir=..\obj
注:配置中的--enable-memcache=shared意思是 memcache 以 dll 形式生成,否則就和php集成在一起了。
如果提示bison.exe不存在,執(zhí)行如下命令,再重新執(zhí)行上面的操作:
set path=%path%;D:\PHPCompile\bin
10、 Configure命令執(zhí)行成功后如下,實際開始編譯前最好檢查下參數(shù)是否有問題:
snapshot: forcing one-shot on snapshot: forcing debug-pack on snapshot: forcing --disable-security-flags shared snapshot: forcing analyzer on snapshot: forcing --without-uncritical-warn-choke shared snapshot: forcing codegen-arch on snapshot: forcing apache2handler on snapshot: forcing apache2-2handler on snapshot: forcing apache2-4handler on snapshot: forcing cli-win32 on snapshot: forcing embed on snapshot: forcing phpdbg on snapshot: forcing phpdbgs on snapshot: forcing --disable-phpdbg-webhelper shared snapshot: forcing bz2 on snapshot: forcing curl on snapshot: forcing dba on snapshot: forcing enchant on snapshot: forcing fileinfo on snapshot: forcing ftp on snapshot: forcing --without-libwebp shared snapshot: forcing gettext on snapshot: forcing gmp on snapshot: forcing mhash on snapshot: forcing imap on snapshot: forcing interbase on snapshot: forcing intl on snapshot: forcing ldap on snapshot: forcing libmbfl on snapshot: forcing mbstring on snapshot: forcing mbregex on snapshot: forcing --disable-mbregex-backtrack shared snapshot: forcing mcrypt on snapshot: forcing oci8 on snapshot: forcing oci8-11g on snapshot: forcing oci8-12c on snapshot: forcing odbc on snapshot: forcing --disable-opcache-file shared snapshot: forcing openssl on snapshot: forcing pgsql on snapshot: forcing pspell on snapshot: forcing shmop on snapshot: forcing snmp on snapshot: forcing sockets on snapshot: forcing sqlite3 on snapshot: forcing sysvshm on snapshot: forcing tidy on snapshot: forcing exif on snapshot: forcing MySQLi on snapshot: forcing pdo on snapshot: forcing pdo-dblib on snapshot: forcing pdo-mssql on snapshot: forcing pdo-firebird on snapshot: forcing pdo-mysql on snapshot: forcing pdo-oci on snapshot: forcing pdo-odbc on snapshot: forcing pdo-pgsql on snapshot: forcing pdo-sqlite on snapshot: forcing pdo-sqlite-external on snapshot: forcing phar-native-ssl on snapshot: forcing soap on snapshot: forcing xmlrpc on snapshot: forcing xsl on Saving configure options to config.nice.bat Checking for cl.exe ... Detected compiler MSVC14 (Visual C++ 2015) Detected 64-bit compiler Checking for link.exe ... C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64 Checking for nmake.exe ... Checking for lib.exe ... Checking for bison.exe ... Checking for re2c.exe ... Detected re2c version 0.13.5 Checking for zip.exe ... Checking for lemon.exe ... Checking for mc.exe ... C:\Program Files (x86)\Windows Kits\8.1\bin\x64 Checking for mt.exe ... C:\Program Files (x86)\Windows Kits\8.1\bin\x64 Enabling multi process build
Build dir: D:\PHPCompile\phpdev\vc14\x64\obj\Release_TS PHP Core: php7ts.dll and php7ts.lib
Checking for wspiapi.h ... Enabling IPv6 support Enabling SAPI sapi\cgi Enabling SAPI sapi\cli Enabling extension ext\date 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 Enabling extension ..\pecl\memcache [shared]
Creating build dirs... Generating files... Generating Makefile Generating main/internal_functions.c [content unchanged; skipping] Generating main/config.w32.h Generating phpize Done.
Enabled extensions: ----------------------- | Extension | Mode | ----------------------- | date | static | | memcache | shared | | pcre | static | | reflection | static | | session | static | | spl | static | | standard | static | -----------------------
Enabled SAPI: ------------- | Sapi Name | ------------- | cgi | | cli | -------------
---------------------------------------------- | | | ---------------------------------------------- | Build type | Release | | Thread Safety | Yes | | Compiler | MSVC14 (Visual C++ 2015) | | Architecture | x64 | | Optimization | PGO disabled | | Static analyzer | disabled | ----------------------------------------------
Type 'nmake snap' to build a PHP snapshot
D:\PHPCompile\phpdev\vc14\x64\php7> |
11、 執(zhí)行nmake命令,等待十幾分鐘,如果沒有問題就會編譯成功,如果有問題,呵呵,那就要根據(jù)錯誤信息一點點排查解決了;
12、 編譯成功后,可在“D:\PHPCompile\phpdev\vc14\x64\obj\Release_TS\”目錄下找到php_memcache.dll;
安裝很簡單,將php_memcache.dll解壓到PHP的EXT目錄下即可。
打開PHP.INI,在一堆extension配置項中另起一行,輸入:
extension=php_memcache.dll
重啟Apache服務(wù)器后,在瀏覽器中打開http://localhost/phpinfo.php,搜索memcache,看到如下內(nèi)容就說明安裝成功了:
https://wiki.php.net/internals/windows/stepbystepbuild#building_pecl_extensions
http://blog.csdn.net/mycwq/article/details/10165955
https://bugs.php.net/bug.php?id=70751