Heim  >  Artikel  >  Backend-Entwicklung  >  Windows WAMP PHP 扩展开发

Windows WAMP PHP 扩展开发

WBOY
WBOYOriginal
2016-07-30 13:31:131091Durchsuche

1.开发准备
  安装WAMP,使用的版本为WampServer Version 2.5,其中PHP的版本为5.5.12。
  WAMP安装目录:D:\wamp
  apache目录:D:\wamp\bin\apache
  php目录:D:\wamp\bin\php
  下载PHP-5.5.12源码包,解压到任意目录。例如:E:\php-5.5.12
2.通过phpinfo()查询php版本的编译的相关信息,主要查看:
  CompilerMSVC11 (Visual C++ 2012)
  Architecturex86
  Zend Extension BuildAPI220121212,TS,VC11
  PHP Extension BuildAPI20121212,TS,VC11
  从以上的信息可以看出WampServer 2.5中的php是通过MSVC11(VS2012)在x86(win32)进行编译且设置了TS(Thread Safe)属性。
  所以在编译扩展插件时也需要使用相同的编译环境及TS设置(默认值为TS)
3.生成编译插件时需要的config.w32.h文件
  打开“VS2012 开发人员命令提示”并进入E:\php-5.5.12目录;
  执行buildconf.bat命令,该命令在当前目录下生成configure.js文件;
  执行configure命令,生成E:\php-5.5.12\main\config.w32.h文件。
  如果执行过程中出现bison相关的错误,说明你没有安装bison,可以打开configure.js文件并注释如下三行,再重新执行configure命令。
  if (!PATH_PROG('bison')) {
ERROR('bison is required')
  }
  为什么可以这么操作,因为我们不需要编译PHP,只需要生成config.w32.h文件,以编译扩展插件。
4.插件编译文件准备
  进入E:\php-5.5.12\ext目录,复制E:\php-5.5.12\ext\skeleton目录并重命名为你所需要开发插件的名字,如my_plugin;
  将php_skeleton.h,skeleton.c和skeleton.dsp重命名为php_my_plugin.h,my_plugin.c和my_plugin.dsp;
  分别打开上面的三个文件,将文件中的extname替换为my_plugin,EXTNAME替换为MY_PLUGIN(保证大小写一致);
  将D:\wamp\bin\php\php5.5.12\dev\php5ts.lib复制到my_plugin目录。
5.编译插件及安装
  使用VS2012打开my_plugin.dsp文件,选择Release_TS(生成Release版本)并配置编译为C代码(解决方案属性-配置属性-C/C++-高级-编译为-编译为 C 代码 (/TC));
  编译解决方案并生成插件所对应的php_my_plugin.dll文件(位于E:\php-5.5.12\Release_TS目录);
  将编译生成的dll文件复制到Wamp PHP扩展目录(D:\wamp\bin\php\php5.5.12\ext);
  编辑D:\wamp\bin\apache\apache2.4.9\bin\php.ini文件,查找"extension="关键字并在PHP原有插件的后面添加"extension=php_my_plugin.dll";
  特别注意:所编辑的php.ini不是D:\wamp\bin\php\php5.5.12\php.ini,因为Wamp初始化PHP时,读取位置在D:\wamp\bin\apache\apache2.4.9\bin\php.ini文件。
  重启Apache服务器。
6.测试插件
  如果插件加载成功,重启Apache服务器访问phpinfo()即可看到新添加的my_plugin插件。
  生成my_plugin_test.php文件,放置到D:\wamp\www目录,文件内容如下:
      echo confirm_my_plugin_compiled("my_plugin");
  ?>
  使用浏览器访问上面新建的my_plugin_test.php文件,出现如下页面,说明插件运行正常:
  Congratulations! You have successfully modified ext/my_plugin/config.m4. Module my_plugin is now compiled into PHP.

版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了Windows WAMP PHP 扩展开发,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:php:图像处理Nächster Artikel:Nginx+Tomcat做负载平衡