1、cd ext
2、./ext_skel --extname=helloworld
3、vim config.m4
去掉注释:
PHP_ARG_WITH(helloworld, for helloworld support,
Make sure that the comment is aligned:
[ --with-helloworld Include helloworld support])
4、/usr/local/php-7.1.0/bin/phpize
5、vim helloworld.c
/*
* #define ZEND_FN(name) zif_##name
* #define ZEND_MN(name) zim_##name
* #define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS)
* #define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(ZEND_FN(name))
* #define INTERNAL_FUNCTION_PARAMETERS zend_execute_data *execute_data, zval *return_value
*
*实际上宏替换的函数为
* zif_helloworld(zend_execute_data *execute_data, zval *return_value)
*
* */
PHP_FUNCTION(confirm_helloworld_compiled)
{
char *arg = NULL;
size_t arg_len, len;
zend_string *strg;
/*
* zend_parse_parameters 是 confirm_helloworld_compiled 所传的参数
*/
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) {
return;
}
strg = strpprintf(0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "helloworld", arg);
RETURN_STR(strg);
}
把函数名改掉 confirm_helloworld_compiled 为helloworld
PHP_FUNCTION(改为helloworld)
const zend_function_entry helloworld_functions[] = {
PHP_FE(helloworld, NULL) /* For testing, remove later. */
PHP_FE_END /* Must be the last line in helloworld_functions[] */
};
6、./configure --with-php-config=/usr/local/php-7.1.0/bin/php-config
7、make && make install
8、修改php.ini
extension=helloworld.so
设置php的配置文件 未设置php配置文件时输入php --ini命令,会出现 [root@liangzai~]# php --ini Configuration File (php.ini) Path: /usr/local/php/lib Loaded Configuration File: (none) Scan for additional .ini files in: (none) Additional .ini files parsed: (none) 在opt的php安装目录下有这两个文件,将其中的production复制到/usr/local/php/lib目录cp /opt/php-7.1.0/php.ini-production /usr/local/php/lib /opt/php-7.1.0/php.ini-development /opt/php-7.1.0/php.ini-production 将php.ini-production重命名为php.ini,再次输入php –ini命令(可以看到已经加载了配置文件,稍后再做具体配置)
9、php -m 看看有没有装上helloworld
|