失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php如何调用c接口无错版

php如何调用c接口无错版

时间:2024-04-20 09:51:04

相关推荐

php如何调用c接口无错版

php教程|php手册

php,如何,调用,接口,无错,版,php,如何,调用,接口,无错,版,首先,是要,安,装好,PHP,进入,下载,解

php教程-php手册

php如何调用c接口无错版

反馈网源码,ubuntu字符界面太小,py爬虫获取小说,php耦合函数,歌曲好seolzw

1.首先是要安装好PHP

博客网站源码 推荐,mac vscode不显示,ubuntu gdb指令,如何看懂tomcat源码,软件连接sqlite数据库,爬虫可以从数据库获取资源吗,php引入php文件路径,云南seo哪个公司好,免费技术资源分享网站,云平台模板lzw

2.进入PHP的下载解压目录下的ext目录

aspnet项目源码,ubuntu下启动u,tomcat一直卡在初始化,python 杭州婚恋爬虫,php系统化框架教程学习交流,昌邑seo推广lzw

#cd /root/php-5.3.6/ext

#./ext_skel –extname=hmc

说明:

./ext_skel –extname=module_name

module_name是你自己可以选择的扩展模块的名字,例如我选择的hmc。执行工具后会自动在ext目录下建立你选择的module_name名字的目录,里面已经生成了相关的代码,这些代码中只需要调整config.m4文件中的三行注释就可以正常的编译带这个自定义扩展模块的php了。

3.修改config.m4

可以将生成的module目录复制到任意希望放置的地方

进入hmc目录

vi config.m4

使用文本编辑器打开config.m4文件

根据你自己的选择将

dnl PHP_ARG_WITH(hmc, for hmc support,

dnl Make sure that 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, whether to enable hmc support,

Make sure that the comment is aligned:

[ –enable-hmc Enable hmc support])

一般我会选择后者,然后保存退出。

4.修改.c和.h文件代码

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

#./configure –enable-hmc

#make

#make install

应该在php的modules目录下有一个hmc.so文件,不同的机器位置会不一样

6.修改PHP配置

编辑php.ini,把扩展加入进去:

在[PHP]模块下增加:

extension = hmc.so

重启Httpd

#service httpd restart

7.php调用

建立一个c.php文件在对应的www目录下

<?

say_hello();

?>

这时浏览器应该输出:

hello world

8.调试

可以在命令行下输入

#php –q c.php

需要进入当前的www目录下

查看是否安装好模块可以用phpinfo()

也可以适用php -m命令

先用

#which php

找到php所在目录,不同机器目录不一样

#/usr/bin/php -m

9.带参数的函数

Vi hmc.c

修改最后的say_hello函数内容如下:

PHP_FUNCTION(say_hello)

{

zval **yourname;

if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &yourname) == FAILURE)

{

WRONG_PARAM_COUNT;

}

zend_printf(“hello world, %s\n”, Z_STRVAL_PP(yourname));

}

修改c.php为

<?

say_hello(“清清月儿”);

?>

如果觉得《php如何调用c接口无错版》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。