https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2php
https://wiki.php.net/internals/windows/stepbystepbuildgit
Visual Studio 2015 社区版本
PHP-sdk-binary-tools-20110915.zip (http://windows.php.net/downloads/php-sdk/下载)
deps-7.0-vc14-x86.7z (https://windows.php.net/downloads/php-sdk/archives/下载)
php-7.0.2 (http://php.net/downloads.php下载)github
第一步windows
D:\vcmyprojects\php-sdk
--bin
--script
--share安全
而后,这个是你已经安装完成了visual studio 2015,打开VS2015开人员命令提示,注意,编译是必定要用这个进,普通的cmd不行,走了不少弯路。。。session
cd D:\vcmyprojects\php-sdk
bin\phpsdk_setvars.bat
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
bin\phpsdk_buildtree.bat phpdev
编译安装phpphp7
回到VS2015开发人员命令提示函数
cd D:\vcmyprojects\php-sdk\phpdev\vc11\x86\php-7.0.2 buildconf
configure --help
configure --disable-all --enable-cli
而后,你会看到Type 'nmake' to build PHP,而后编译工具
nmake
在D:\vcmyprojects\php-sdk\phpdev\vc11\x86\php-7.0.2\Release_TS文件夹下就生成了php.exe文件,环境变量中加入这个路径,好在命令行中能使用php命令。性能
开发PHP的第一个扩展
cd D:\vcmyprojects\php-sdk\phpdev\vc11\x86\php-7.0.2\ext php ext_skel_win32.php --extname=raintest1
这时候咱们在D:\vcmyprojects\php-sdk\phpdev\vc11\x86\php-7.0.2\ext就看到了本身的目录raintest1,打开raintest1\php_raintest1.h,在
打开ext\就会看到一个test文件夹,这个就是你的扩展。
加入如下几个php源码目录(实际目录以开发者本身的目录为准):
E:\php-xxx-src E:\php-xxx-src\main E:\php-xxx-src\TSRM E:\php-xxx-src\Zend
右键项目属性,C/C++,预处理器,预处理器定义,编辑,加入如下变量:
ZEND_DEBUG=0 PHP_EXTENSION PHP_WIN32 ZEND_WIN32 HAVE_XXX=1 COMPILE_DL_XXX ZTS 注意,要把上面的 XXX 改成大写的扩展名 (如扩展叫 tonyenc 就把 XXX 改为 TONYENC),不然 PHP 将没法识别扩展。ZTS用于告诉编译器开启线程安全(若是去掉就是不开启)。注意,线程安全的开启与否,取决于前面下载到的 C:\php7-Win32-VC14-x64-ts,它也是启用了线程安全编译,因此这里开启线程安全。
#define PHP_COMPILER_ID "VC14"
这将指明运行库是 VC14,与前面下载到的已编译 PHP 程序匹配,从新生成下解决方案,这样就能成功编译了!
打开test.c
找到这一段代码:
PHP_FUNCTION(confirm_test_compiled) { char *arg = NULL; int arg_len, len; char *strg; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { return; } len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "test", arg); RETURN_STRINGL(strg, len, 0); }
将confirm_test_compiled改为test_echo
再找到这一段代码:
const zend_function_entry test_functions[] = { PHP_FE(confirm_test_compiled, NULL) /* For testing, remove later. */ PHP_FE_END /* Must be the last line in test_functions[] */ };
将里面的confirm_test_compiled也改为test_echo
生成解决方案,在项目根目录的Release文件夹里找到本身的php扩展phptest.dll,复制到php的ext文件夹里,在php.ini里配置上:
extension=phptest.dll
重启IIS,新建一个站点,在里面新建一个test.php文件
<?php echo test_echo("123");
运行获得结果:
这个test_echo函数,就是咱们本身的自定义函数了,你也能够根据需求,开发本身的扩展来提升php的性能。
nmake clean buildconf --force configure --disable-all --enable-cli --enable-memcache=shared --enable-session --enable-zlib nmake
php -c tmp-php.ini -m