phpµ÷ÓÃc½Ó¿ÚÎÞ´í°æ½éÉÜ

5年以前  |  阅读数:937 次  |  编程语言:PHP 

**1.Ê×ÏÈÊÇÒª°²×°ºÃPHP

2.½øÈePHPµÄÏÂÔؽaѹĿ¼ÏµÄextĿ¼
**#cd /root/php-5.3.6/ext

./ext_skel --extname=hmc

˵Ã÷£º
./ext_skel --extname=module_name
module_nameÊÇÄa×Ô¼º¿ÉÒÔÑ¡ÔñµÄÀ(C)չģ¿eµÄÃu×Ö£¬ÀýÈçÎÒÑ¡ÔñµÄhmc¡£Ö´Ðй¤¾ßºo»a×Ô¶¯ÔÚextĿ¼Ï½¨Á¢ÄaÑ¡ÔñµÄmodule_nameÃu×ÖµÄĿ¼£¬ÀiÃaeÒѾ­Éu³ÉÁËÏa¹ØµÄ´uÂe£¬ÕaÐ(C)´uÂeÖÐÖ»ÐeÒªµ÷Õuconfig.m4ÎļþÖеÄÈýÐÐ×¢Ê;ͿÉÒÔÕý³£µÄ±aÒe´øÕa¸o×Ô¶¨ÒaÀ(C)չģ¿eµÄphpÁË¡£

3.ÐÞ¸Äconfig.m4
¿ÉÒÔ½«Éu³ÉµÄmoduleĿ¼¸´ÖƵ½ÈÎÒaÏ£ÍuÅÖõĵؽ
½øÈehmcĿ¼
vi config.m4
ʹÓÃÎı¾±a¼­Æ÷´o¿ªconfig.m4Îļþ
¸u¾ÝÄa×Ô¼ºµÄÑ¡Ôñ½«
dnl PHP_ARG_WITH(hmc, for hmc support,
dnl Make sure that the comment is aligned:
dnl [ --with-hmc Include hmc support])
Ð޸ijÉ
PHP_ARG_WITH(hmc for hmc support,
Make sure that the comment is aligned:
[ --with-hmc Include hmc support])
»oÕß½«
dnl PHP_ARG_ENABLE(hmc, whether to enable hmc support,
dnl Make sure that the comment is aligned:
dnl [ --enable-hmc Enable hmc support])
Ð޸ijÉ
PHP_ARG_ENABLE(hmc, whether to enable hmc support,
Make sure that the comment is aligned:
[ --enable-hmc Enable hmc support])

Ò»°aÎÒ»aÑ¡ÔñºoÕߣ¬È»ºo±£´aeÍ˳o¡£

4.ÐÞ¸Ä.cºÍ.hÎļþ´uÂe
Vi hmc.c
½«ÎļþÆaÖеÄÏÂÁдuÂe½øÐÐÐÞ¸Ä
/ Every user visible function must have an entry in hmc_functions[].
/
const zend_function_entry hmc_functions[] = {
PHP_FE(say_hello, NULL) / Ìi¼Ó×ÅÒ»ÐдuÂe /
PHP_FE(confirm_hmc_compiled, NULL) / For testing, remove later. /
{NULL, NULL, NULL} / Must be the last line in hmc_functions[] /
};

ÔÚÎļþµÄ×iºoÌi¼ÓÏÂÁдuÂe
PHP_FUNCTION(say_hello)
{
zend_printf("hello world\n");
}
±£´aeÎļþÍ˳o

vi php_hmc.h
ÔÚÎļþÖÐPHP_FUNCTION(confirm_hmc_compiled);Ò»ÐÐÇ°ÃaeÌi¼ÓÏÂÃaeµÄ´uÂe
PHP_FUNCTION(say_hello);
±£´aeÎļþÍ˳o

5.±aÒe°²×°
#phpize

./configure --enable-hmc

make

make install

Ó¦¸ÃÔÚphpµÄmodulesĿ¼ÏÂÓÐÒ»¸ohmc.soÎļþ,²»Í¬µÄ»uÆ÷λÖûa²»Ò»Ñu

6.ÐÞ¸ÄPHPÅaÖÃ
±a¼­php.ini£¬°ÑÀ(C)Õ¹¼ÓÈe½øÈ¥£º
ÔÚ[PHP]Ä£¿eÏÂÔo¼Ó£º
extension = hmc.so
ÖØÆoHttpd

service httpd restart

7.phpµ÷ÓÃ
½¨Á¢Ò»¸oc.phpÎļþÔÚ¶ÔÓ¦µÄwwwĿ¼ÏÂ
<?
say_hello();
?>
Õaʱa¯ÀÀÆ÷Ó¦¸ÃÊa³o£º
hello world

8.µ÷ÊÔ
¿ÉÒÔÔÚÃuÁiÐÐÏÂÊaÈe

php ¨Cq c.php

ÐeÒª½øÈeµ±Ç°µÄwwwĿ¼ÏÂ

²e¿´ÊÇ*ñ°²×°ºÃÄ£¿e¿ÉÒÔÓÃphpinfo()

Ò²¿ÉÒÔÊÊÓÃphp -mÃuÁi
ÏÈÓÃ

which php

ÕÒµ½phpËuÔÚĿ¼£¬²»Í¬»uÆ÷Ŀ¼²»Ò»Ñu

/usr/bin/php -m

9.´ø²ÎÊýµÄº¯Êý
Vi hmc.c
ÐÞ¸Ä×iºoµÄ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(¡°ÇaÇaÔ¶u");
?>

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例