欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php調(diào)用c接口無錯(cuò)版介紹

 更新時(shí)間:2014年03月11日 09:54:45   作者:  
本篇文章主要是對(duì)php調(diào)用c接口無錯(cuò)版進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助

1.首先是要安裝好PHP

2.進(jìn)入PHP的下載解壓目錄下的ext目錄
#cd /root/php-5.3.6/ext
#./ext_skel --extname=hmc

說明:
./ext_skel --extname=module_name
module_name是你自己可以選擇的擴(kuò)展模塊的名字,例如我選擇的hmc。執(zhí)行工具后會(huì)自動(dòng)在ext目錄下建立你選擇的module_name名字的目錄,里面已經(jīng)生成了相關(guān)的代碼,這些代碼中只需要調(diào)整config.m4文件中的三行注釋就可以正常的編譯帶這個(gè)自定義擴(kuò)展模塊的php了。

3.修改config.m4
可以將生成的module目錄復(fù)制到任意希望放置的地方
進(jìn)入hmc目錄
vi config.m4
使用文本編輯器打開config.m4文件
根據(jù)你自己的選擇將
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])

一般我會(huì)選擇后者,然后保存退出。

4.修改.c和.h文件代碼
Vi hmc.c
將文件其中的下列代碼進(jìn)行修改
/* 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
應(yīng)該在php的modules目錄下有一個(gè)hmc.so文件,不同的機(jī)器位置會(huì)不一樣



6.修改PHP配置
編輯php.ini,把擴(kuò)展加入進(jìn)去:
在[PHP]模塊下增加:
extension = hmc.so
重啟Httpd
#service httpd restart

7.php調(diào)用
建立一個(gè)c.php文件在對(duì)應(yīng)的www目錄下
<?
say_hello();
?>
這時(shí)瀏覽器應(yīng)該輸出:
hello world

8.調(diào)試
可以在命令行下輸入
#php –q c.php
需要進(jìn)入當(dāng)前的www目錄下

查看是否安裝好模塊可以用phpinfo()



也可以適用php -m命令
先用
#which php
找到php所在目錄,不同機(jī)器目錄不一樣
#/usr/bin/php -m


9.帶參數(shù)的函數(shù)
Vi hmc.c
修改最后的say_hello函數(shù)內(nèi)容如下:
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(“清清月兒");
?>

相關(guān)文章

最新評(píng)論