概述

PHP 7.2出来有一段时间了,不出意料,memcache又不能用了,于是又想到要自己动手编译,不过与我编译PHP 7.1的memcache的时候相比,有个好消息是已经有人把PHP 7.1和7.2 的memcache都编译好并放在github上了,需要的可直接去那里下载,我这篇文章就不提供下载了:
https://github.com/nono303/PHP7-memcache-dll

注:这里还是要强烈吐槽一下百度,以“php 7.2 memcache”为关键字,完全搜索不到任何有用的东西,上面那个网址我是用google一下子就搜到了,而且还受到启发,顺利的把编译过程给搞定,所以搞开发的遇到技术问题,还是不要在百度上浪费生命了。

我下面还是把我研究出来的PHP 7.2 memcache的编译方法写出来,给有需要的人做个参考吧。

PHP 7.2的memcache编译方法跟之前版本有了一些变化,主要体现在:

PHP SDK的下载路径与编译方式发生了改变;PHP 7.2的memcache要使用VC15编译;下载文件

编译前需要下载如下文件:

编译环境:
PHP-memcached是用VC15编译的,因为并不常用VC15,所以到微软的官网上下载visual studio 2017 entrpise的试用版即可。
地址:
https://www.visualstudio.com/zh-hans/?rr=https%3A%2F%2Fwww.microsoft.com%2Fzh-cn%2FPHP源代码:
从PHP官网上下载源代码,地址:
http://windows.php.net/downloads/releases/php-7.2.0-src.zip下载PHP-SDK文件:
原来的网址里,已经没有PHP 7.2的SDK包下载,根据其页面上的Readme.txt的说明,要到如下地址去下载:
https://github.com/Microsoft/php-sdk-binary-tools下载memcache扩展包的源码,这个地址也换了,如下:
https://github.com/websupport-sk/pecl-memcache/tree/NON_BLOCKING_IO_php7准备PHP代码

注意:编译前需先安装好vs2017。

新建一个编译目录,如PHP72Compile;将从https://github.com/Microsoft/php-sdk-binary-tools 下载的包解压到这个目录,目录结构如下:
打开cmd窗口,进入到PHP72Compile目录;执行phpsdk-vc15-x64.bat,结果如下图:
再运行:phpsdk_buildtree phpdev,结果如下图:
在此路径下建立php-src目录,并将下载的PHP源码拷贝到这个目录,最终目录结构如下:
在命令行进入到php-src目录,结果如下图:
执行命令:phpsdk_deps --update --branch master,用来获取SDK的依赖包,输出信息如下:

D:\PHP72Compile\phpdev\vc15\x64\php-src$ phpsdk_deps --update --branch masterConfiguration: master-vc15-x64-stagingProcessing package ICU-60.1-1-vc15-x64.zipProcessing package apache-2.4.28-vc15-x64.zipProcessing package c-client-2007f-vc15-x64.zipProcessing package fbclient-3.0-nocrt-x64.zipProcessing package freetype-2.8.0-1-vc15-x64.zipProcessing package glib-2.53.3-vc15-x64.zipProcessing package libargon2-20161029-vc15-x64.zipProcessing package libbzip2-1.0.6-vc15-x64.zipProcessing package libcurl-7.56.0-2-vc15-x64.zipProcessing package libenchant-1.6.0-vc15-x64.zipProcessing package libffi-3.2.1-vc15-x64.zipProcessing package libiconv-1.15-1-vc15-x64.zipProcessing package libintl-0.18.3-1-vc15-x64.zipProcessing package libjpeg-9b-vc15-x64.zipProcessing package liblmdb-0.9.21-vc15-x64.zipProcessing package libpng-1.6.34-vc15-x64.zipProcessing package libpq-9.6.5-vc15-x64.zipProcessing package libqdbm-1.8.78-vc15-x64.zipProcessing package libsasl-2.1.27-vc15-x64.zipProcessing package libssh3-1.8.0-vc15-x64.zipProcessing package libtidy-5.4.0-vc15-x64.zipProcessing package libwebp-0.6.0-vc15-x64.zipProcessing package libxml2-2.9.5-vc15-x64.zipProcessing package libxpm-3.5.12-1-vc15-x64.zipProcessing package libxslt-1.1.30-vc15-x64.zipProcessing package libzip-1.3.0-v15-x64.zipProcessing package mpir-3.0.0-vc15-x64.zipProcessing package net-snmp-5.7.3-vc15-x64.zipProcessing package nghttp2-1.24.0-vc15-x64.zipProcessing package openldap-2.4.45-vc15-x64.zipProcessing package openssl-1.1.0g-vc15-x64.zipProcessing package wineditline-2.202-vc15-x64.zipProcessing package zlib-1.2.11-vc15-x64.zipProcessing package libsodium-1.0.15-vc15-x64.zipUpdates performed successfully.Old dependencies backed up into 'D:\PHP72Compile\phpdev\vc15\x64\deps.201712260650'.D:\PHP72Compile\phpdev\vc15\x64\php-src$准备PHP memcache代码在与php-src同级的目录下建立pecl\memcache目录,并将下载的php-memcache代码放到这个目录下,效果如下图:
执行buildconf命令,效果如下图:
执行命令:

configure --disable-all --enable-cli --enable-zlib --enable-hash --enable-session --without-gd --with-bz2 --enable-memcache=shared --enable-fd-setsize=2048 --enable-sanitizer

输出信息如下:

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-sanitizerPHP Version: 7.2.0Saving configure options to config.nice.batChecking for cl.exe ... <in default path>WARNING: Using unknown MSVC version 19.12.25831 Detected compiler MSVC 19.12.25831, untested Detected 64-bit compilerChecking for link.exe ... C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\bin\HostX64\x64Checking 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.2Checking 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\x64Checking for mt.exe ... C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x64Enabling multi process buildBuild dir: D:\PHP72Compile\phpdev\vc15\x64\php-src\x64\Release_TSPHP Core: php7ts.dll and php7ts.libChecking for wspiapi.h ... <in default path>Enabling IPv6 supportEnabling SAPI sapi\cliChecking for library edit_a.lib;edit.lib ... ..\deps\lib\edit_a.libChecking for editline/readline.h ... D:\PHP72Compile\phpdev\vc15\x64\deps\includeChecking for library libbz2_a.lib;libbz2.lib ... ..\deps\lib\libbz2_a.libChecking for bzlib.h ... D:\PHP72Compile\phpdev\vc15\x64\deps\includeEnabling extension ext\bz2Enabling extension ext\dateChecking for KeccakHash.h ... ext/hash/sha3/generic64lcEnabling extension ext\hashEnabling extension ext\pcreEnabling extension ext\reflectionEnabling extension ext\sessionEnabling extension ext\splChecking for timelib_config.h ... ext/date/libEnabling extension ext\standardChecking for library zlib_a.lib;zlib.lib ... ..\deps\lib\zlib_a.libChecking for zlib.h ... D:\PHP72Compile\phpdev\vc15\x64\deps\includeEnabling extension ext\zlibEnabling extension ..\pecl\memcache\php7 [shared]Creating build dirs...Generating files...Generating MakefileGenerating main/internal_functions.cGenerating main/config.w32.hGenerating phpizeDone.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 PHPD:\PHP72Compile\phpdev\vc15\x64\php-src$编译与查看执行nmake开始编译,,等待几分钟或十几分钟,中间会报若干警告,不用理会;编译完成后,在“D:\PHP72Compile\phpdev\vc15\x64\php-src\x64\Release_TS\”目录下可找到php_memcache.dll。