Linux下开发php扩展的方法
- 首先按照上一篇缩写的搭建好LAMP开发环境
- 进入到php的安装源文件目录下,我的是在/home/keyboard下
- 进入到php-5.2.5目录下的ext文件夹下


4. 执行如下命令 ./ext_skel --extname=myext

5.cd myext
6.vi config.m4
去掉dnl获得如下信息
保存退出

7. vi php_myext.h
找到:PHP_FUNCTION(confirm_heiyeluren_compiled); ,新增一行:
PHP_FUNCTION(hello);

8.vi php_myext.c
数组里增加我们的函数,找到 zend_function_entry heiyeluren_functions[],增加:
PHP_FE(heiyeluren, NULL)
再到 heiyeluren.c 文件最后面增加如下代码:
PHP_FUNCTION(heiyeluren_test)
{
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, "Hello: %s\n", arg);
RETURN_STRINGL(strg, len, 0);
}
保存退出。

9.在myext目录下执行 /usr/local/php/bin/phpize
10. ./configure --with-php-config=/usr/local/php/bin/php-config
11.make
12.make test
13.make install
现在在/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/目录下会有一个myext.so文件,就是我们生成的扩展文件
在php.ini文件中配置如下参数
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension=myext.so
保存退出
重启apache服务器,这样我们开发的扩展中的函数就可以在php文件中使用了
浙公网安备 33010602011771号