时间:2021-07-01 10:21:17 帮助过:7人阅读
- <br>dnl Otherwise use enable: <br>PHP_ARG_ENABLE(laiwenhui, whether to enable laiwenhui support, <br>dnl Make sure that the comment is aligned: <br>[ --enable-laiwenhui Enable laiwenhui support]) <br> <br><br><strong>第三步:编写代码 <br><br></strong>vim php_laiwenhui.h <br><br>在 PHP_FUNCTION(confirm_laiwenhui_compiled); 后面新增一行:PHP_FUNCTION(test); <br><br>添加后为: <br><br>PHP_FUNCTION(confirm_laiwenhui_compiled); /* For testing, remove later. */ <br>PHP_FUNCTION(test); <br><br>然后 <br><br>vim laiwenhui.c <br><br>在PHP_FE(confirm_laiwenhui_compiled, NULL) 后面添加 PHP_FE(test, NULL) <br><br>添加后为: <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>zend_function_entry laiwenhui_functions[] = { <br>PHP_FE(confirm_laiwenhui_compiled, NULL) /* For testing, remove later. */ <br>PHP_FE(test, NULL) /* For testing, remove later. */ <br>{NULL, NULL, NULL} /* Must be the last line in laiwenhui_functions[] */ <br>}; <br> <br>在文件最后面增加如下代码: <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>PHP_FUNCTION(test) <br>{ <br>char *arg = “This my first extention!”; <br>int len; <br>char *strg; <br>len = spprintf(&strg, 0, “%s\n”, arg); <br>RETURN_STRINGL(strg, len, 0); <br>} <br> <br><strong>第四步:编译代码 <br></strong><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br>cd php-5.2.6/ext/laiwenhui <br>/opt/module/php/bin/phpize <br>./configure –with-php-config=/opt/module/php/bin/php-config <br>make <br>make install <br> <br>我的PHP安装路径为:/opt/module/php <br>这个时候会生成一个文件 /opt/module/php/lib/php/extensions/no-debug-non-zts-20060613/laiwenhui.so <br><br>编辑PHP配置文件php.ini,添加扩展: <br><br>vim php.ini <br><br>在[PHP]模块下增加:extension = laiwenhui.so <br><br>;extension=php_zip.dll <br>extension = laiwenhui.so <br><br>把php.ini 文件中的 extension_dir 修改为该目录: <br>extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/” <br><br>; Directory in which the loadable extensions (modules) reside. <br>extension_dir = “/opt/module/php/lib/php/extensions/no-debug-non-zts-20060613/” <br><br><strong>第五步:检查安装结果</strong> <br><br>1. 重启apache或者php-fpm <br>2. /opt/module/php/bin/php -m 看下是否有包含laiwenhui扩展。 <br>第六步:执行测试代码 <br><br>在网站根目录创建test.php <br><br>vim test.php <br><br>代码内容如下 <br><br><!--?php <BR-->echo test(); <br>?> <br><br>执行后</li></ol></pre>结果为:This my first extention! <br><br>如果你能顺利完成以上几步,恭喜你完成了第一个扩展。 <br><br>以上是扩展PHP的简单步骤,更多请参考: </li></ol></pre></li></ol></pre>