[php5.6]php扩展开发入门–helloworld

 

首先需要下载php源码

1,生成扩展骨架 php-5.6.30/ext$ ./ext_skel –extname=helloWorld
同时产生操作步骤
1. $ cd ..
2. $ vi ext/helloWorld/config.m4
3. $ ./buildconf
4. $ ./configure –[with|enable]-helloWorld
5. $ make
6. $ ./sapi/cli/php -f ext/helloWorld/helloWorld.php
7. $ vi ext/helloWorld/helloWorld.c
8. $ make

2,vim config.m4
把第10-13行
PHP_ARG_WITH(helloWorld, for helloWorld support,
Make sure that the comment is aligned:
[ –with-helloWorld Include helloWorld support])
注释dnl去掉

132b2005134ec7d02ac7b8137212d5c3

3,./buildconf –force
4,./configure –with-helloWorld
5 make 可选
6,进入到扩展vim helloWorld.c
修改144-147行
照着添加一个方法定义
PHP_FE(helloWorld, NULL)

同时添加一个实现
PHP_FUNCTION(helloWorld)
{
char *arg = NULL;
int arg_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, “s”, &arg, &arg_len) == FAILURE) {
return;
}
RETURN_STRINGL(arg, arg_len, 0);

}

7 正常的添加扩展步骤
1)phpize
2)./configure –with-php-config=/home/users/wangchunwei/php/bin/php-config
3) make
4) make install

 

剩下的步骤就是配置php.ini的扩展,添加helloWorld.so。之后调用helloWorld(“string”)方法,亲测可用!

发表评论

电子邮件地址不会被公开。 必填项已用*标注


*