日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

php如何调用c接口无错版

發布時間:2023/11/27 生活经验 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php如何调用c接口无错版 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.首先是要安裝好PHP

?

2.進入PHP的下載解壓目錄下的ext目錄

#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(“清清月兒");
?>

====================================

?

可以參考以下:

http://www.phpchina.com/index.php?action-viewthread-tid-26870

http://blog.csdn.net/taft/article/details/596291

http://blog.csdn.net/heiyeshuwu/article/details/3453854

http://blog.csdn.net/xiaocon/article/details/388953

一本書《Extending and Embedding PHP》:http://ishare.iask.sina.com.cn/f/14424739.html

?

總結

以上是生活随笔為你收集整理的php如何调用c接口无错版的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。