**1.Ê×ÏÈÊÇÒª°²×°ºÃPHP
2.½øÈePHPµÄÏÂÔؽaѹĿ¼ÏµÄextĿ¼
**#cd /root/php-5.3.6/ext
˵Ã÷£º
./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
Ó¦¸ÃÔÚphpµÄmodulesĿ¼ÏÂÓÐÒ»¸ohmc.soÎļþ,²»Í¬µÄ»uÆ÷λÖûa²»Ò»Ñu
6.ÐÞ¸ÄPHPÅaÖÃ
±a¼php.ini£¬°ÑÀ(C)Õ¹¼ÓÈe½øÈ¥£º
ÔÚ[PHP]Ä£¿eÏÂÔo¼Ó£º
extension = hmc.so
ÖØÆoHttpd
7.phpµ÷ÓÃ
½¨Á¢Ò»¸oc.phpÎļþÔÚ¶ÔÓ¦µÄwwwĿ¼ÏÂ
<?
say_hello();
?>
Õaʱa¯ÀÀÆ÷Ó¦¸ÃÊa³o£º
hello world
8.µ÷ÊÔ
¿ÉÒÔÔÚÃuÁiÐÐÏÂÊaÈe
ÐeÒª½øÈeµ±Ç°µÄwwwĿ¼ÏÂ
²e¿´ÊÇ*ñ°²×°ºÃÄ£¿e¿ÉÒÔÓÃphpinfo()
Ò²¿ÉÒÔÊÊÓÃphp -mÃuÁi
ÏÈÓÃ
ÕÒµ½phpËuÔÚĿ¼£¬²»Í¬»uÆ÷Ŀ¼²»Ò»Ñu
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");
?>