PHP 7出来后,http://pecl.php.net/package/memcache上没有for PHP7的PHP-memcache版本,需要自己编译一个。网上找到的大多是在linux下的,而我需要的是windows下的版本,找了好久没也没有找到合适的版本,只好自己动手了。
创新互联公司-专业网站定制、快速模板网站建设、高性价比杭锦后网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式杭锦后网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖杭锦后地区。费用合理售后完善,十多年实体公司更值得信赖。
注:本文讲的是编译PHP-memcache,而不是memcached。
编译前需要子下载如下文件:
1、 编译环境:
PHP 7是用VC14编译的,因此编译PHP-memcached也需要使用VC14,因为并不常用VC14,所以到微软的官网上下载visual studio 2015 entrpise的试用版即可。
2、 PHP源代码:
从PHP官网上下载源代码,地址: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官网已经N年没有更新了,上面这个网址是github上的支持PHP 7的分支代码。
1、 创建一个用于编译的目录: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年代久远,还不支持VC14,因此需要进行如此修改。
4、 在开始菜单找到并打开“VS2015 x64 本机工具命令提示符”(注:如果要编译32位的,则需进入VS2015 x86 本机工具命令提示符),进入到D:\PHPCompile目录下,然后执行如下命令:
bin\phpsdk_setvars.bat
bin\phpsdk_buildtree.bat phpdev
5、 执行后,目录下会生成phpdev文件夹;
6、 进入D:\PHPCompile\phpdev\vc14\x64\,把deps-7.0-vc14-x64.7z解压到该目录下,覆盖deps文件夹
7、 把php源代码也解压到x64目录下,将解压后的目录名改为PHP7;
8、 在x64目录下创建pecl文件夹,在该文件夹下再建立memcache文件夹,将下载的PHP7-memcache代码解压到这个目录下,最终的目录结构如下:
9、 执行以下命令,用于创建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不存在,执行如下命令,再重新执行上面的操作:
set path=%path%;D:\PHPCompile\bin
10、 Configure命令执行成功后如下,实际开始编译前最好检查下参数是否有问题:
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、 执行nmake命令,等待十几分钟,如果没有问题就会编译成功,如果有问题,呵呵,那就要根据错误信息一点点排查解决了;
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服务器后,在浏览器中打开http://localhost/phpinfo.php,搜索memcache,看到如下内容就说明安装成功了:
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