脚本宝典收集整理的这篇文章主要介绍了php调用c接口无错版介绍,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1.首先是要安装好PHP2.进入PHP的下载解压目录下的ext目录
#cd /root/
PHP-5.3.6/ext
#./ext_skel --extn
ame=hmc说明:
./ext_skel --extname=module_name
module_name是你自己可以选择的
扩展模块的名字,例如我选择的hmc。执行工具后会
自动在ext目录下建立你选择的module_name名字的目录,里面已经
生成了相关的
代码,这些
代码中只需要
调整con
fig.m4
文件中的三行注释就可以
正常的编译带这个
自定义扩展模块的
PHP了。
可以将
生成的module目录复制到任意希望放置的地方
进入hmc目录
vi con
fig.m4
使用文本编辑器打开con
fig.m4
文件根据你自己的选择将
dnl
PHP_
arg_W
ITH(hmc,for hmc support,
dnl Make sure t
hat the comment is aligned:
dnl [ --with-hmc Include hmc support])
修改成
PHP_ARG_WITH(hmc for hmc support,
Make sure that the comment is aligned:
[ --with-hmc Include hmc support])
或者将
dnl
PHP_ARG_ENABLE(hmc,whether to enable hmc support,
dnl Make sure that the comment is aligned:
dnl [ --enable-hmc Enable hmc support])
修改成
PHP_ARG_ENABLE(hmc,
Make sure that the comment is aligned:
[ --enable-hmc Enable hmc support])
一般我会选择后者,然后保存退出。
Vi hmc.c
将
文件其中的下列
代码进行
修改/* Every user visible function must have an entry in hmc_functions[].
*/
const zend_function_entry hmc_functions[] = {
PHP_FE(say_hello,NULL) /*
添加着一行
代码 */
PHP_FE(confirm_hmc_compiled,NULL) /* For
testing,remove later. */
{NULL,NULL,NULL} /* Must be the last line in hmc_functions[] */
};
在文件的最后添加下列代码
PHP_FUNCTION(say_hello)
{
zend_PRintf("hello world\n");
}
保存文件退出
vi PHP_hmc.h
在文件中PHP_FUNCTION(confirm_hmc_compiled);一行前面添加下面的代码
PHP_FUNCTION(say_hello);
保存文件退出
5.编译安装
#
PHPize
#./con
figure --enable-hmc
#make#make install
应该在
PHP的modules目录下有
一个hmc
.so文件,不同的机器位置会不一样
<img title="php调用c接口无错版介绍" alt="php调用c接口无错版介绍" src="https://files.js-code.cc/file_images/article/201403/20140311094817.png">
编辑
PHP.ini,把扩展加入进去:
在[
PHP]模块下
增加:
extension = hmc
.so重启Httpd
#service httpd restart
建立
一个c.
PHP文件在对应的www目录下
<>
say_hello();
?>
这时浏览器应该
输出:
hello world
8.调试
可以在命令行下输入
#
PHP –q c.
PHP需要进入当前的www目录下
查看是否安装好模块可以用PHPinfo()
403/20140311094934.png">也可以适用
PHP -m命令
先用
#
which PHP找到
PHP所在目录,不同机器目录不一样
#/usr/bin/
PHP -m
403/20140311095049.png">
9.带参数的函数
Vi hmc.c
修改最后的say_hello
函数内容如下:
PHP_FUNCTION(say_hello)
{
zval **yourname;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1,&yourname)
== F
aiLURE)
{
WRONG_PARAM_COUNT;
}
zend_printf("hello world,
%s\n",Z_STRVAL_PP(yourname));
}
修改c.PHP为
<>
say_hello(“清清月儿");
?>
脚本宝典总结
以上是脚本宝典为你收集整理的php调用c接口无错版介绍全部内容,希望文章能够帮你解决php调用c接口无错版介绍所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。