background image

修改头文件 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 文件:
 
<?php
myext();