1.进入php源码ext目录下
./ext_skel --extname=helloworld
如果一切顺利,你将看到
2.
cd helloworld
修改config.m4文件,把dnl去掉如下
3.执行phpize (php目录/bin/phpize)
如果顺利你将看到这么多文件
4.修改php_helloworld.h
PHP_FUNCTION(confirm_helloworld_compiled);修改为PHP_FUNCTION(helloworld);//php方法名
5.修改helloworld.c
PHP_FUNCTION(confirm_helloworld_compiled){
char *arg = NULL;
int arg_len, len;
char *strg;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
return;
}
len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "helloworld", arg);
RETURN_STRINGL(strg, len, 0);
}
改为:
PHP_FUNCTION(helloworld)
{
char *arg = "hello world!!!";
int len;
char *strg;
len = spprintf(&strg, 0, "%s\n", arg);
RETURN_STRINGL(strg, len, 0);
}
PHP_FE(confirm_helloworld_compiled, NULL)改为 PHP_FE(helloworld, NULL)
6.执行./configure
7.执行make
8.执行make install
如果顺利你将看到
PS:由于某些原因必须打马赛克。。
9.修改php.ini
增加extension=helloworld.so
10.重启php
php -m 你将看到helloworld
11.test
PS:附上php5.2.17源码下载地址
http://pan.baidu.com/s/1dDHw49r