时间:2021-07-01 10:21:17 帮助过:9人阅读
//或者将 //(不依赖外部库) dnl PHP_ARG_ENABLE(myext, whether to enable myext support,dnl Make sure that the comment is aligned:dnl [ --enable-myext Enable myext support])//去掉dnl
修改头文件php_myext.h:
//PHP_FUNCTION(confirm_myext_compiled); /* For testing, remove later. */
//修改为
PHP_FUNCTION(myext); /* For testing, remove later. */
修改myext.c:
//将
//zend_function_entry myext_functions[] = {
// PHP_FE(confirm_myext_compiled, NULL) /* For testing, remove later. */
// {NULL, NULL, NULL} /* Must be the last line in myext_functions[] */
//};
//修改为
zend_function_entry myext_functions[] = {
PHP_FE(myext, NULL) /* For testing, remove later. */
{NULL, NULL, NULL} /* Must be the last line in myext_functions[] */
};
//在文件底部添加自己的函数
PHP_FUNCTION(myext)
{
zend_printf("Hello World!\n");
}
安装自己的php扩展myext:
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
修改php.ini,添加:
extension = "myext.so"
重启web服务器,查看phpinfo,即可看到自己的扩展:
新建测试php文件:
myext();
执行此文件,即可看到再熟悉不过的“Hello World!”。