php 创建一个扩展开发环境的正确姿势

来源:互联网 发布:odis工程师刷低层数据 编辑:程序博客网 时间:2024/06/05 05:52

安装编译PHP

官网下载最新php-7.1.5.tar的源码包

设置开发目录,打开调试模式,禁止其他内置模块

cd path/to/php-src./configure --prefix=path/to/php --enable-debug --disable-allmake && make install

生成PHP扩展目录

cd php-src/ext./ext_skel --extname=my_helloworldCreating directory my_helloworldCreating basic files: config.m4 config.w32 .gitignore my_helloworld.c php_my_helloworld.h CREDITS EXPERIMENTAL tests/001.phpt my_helloworld.php [done].To use your new extension, you will have to execute the following steps:1.  $ cd ..2.  $ vi ext/my_helloworld/config.m43.  $ ./buildconf4.  $ ./configure --[with|enable]-my_helloworld5.  $ make6.  $ ./sapi/cli/php -f ext/my_helloworld/my_helloworld.php7.  $ vi ext/my_helloworld/my_helloworld.c8.  $ makeRepeat steps 3-6 until you are satisfied with ext/my_helloworld/config.m4 andstep 6 confirms that your module is compiled into PHP. Then, start writingcode and repeat the last two steps as often as necessary.

编辑扩展文件config.m4

去掉这几行的 dnl 注释前缀

PHP_ARG_ENABLE(my_helloworld, whether to enable my_helloworld support,Make sure that the comment is aligned:[  --enable-my_helloworld           Enable my_helloworld support])

编译扩展

cd my_helloworld/path/to/php/bin/phpizeConfiguring for:PHP Api Version:         20160303Zend Module Api No:      20160303Zend Extension Api No:   320160303./configure --enable-my_helloworld --with-php-config=/path/to/php/bin/php-configmake && make install


测试扩展

修改php.ini文件,添加一行记录

extension=my_helloworld.so

测试安装结果

path/to/bin/php my_helloworld.phpFunctions available in the test extension:confirm_my_helloworld_compiledCongratulations! You have successfully modified ext/my_helloworld/config.m4. Module my_helloworld is now compiled into PHP.

测试加载模块

path/to/bin/php -m[PHP Modules]Coredatemy_helloworldpcreReflectionSPLstandard[Zend Modules]



原创粉丝点击