用来编译c文件
输入echo /usr/local/lib > /etc/ld.so.conf.d/local.conf 将/usr/local/lib目录作为so的存放库
在/data目录下新建文件gx.c
int gx(int a)
{
return a;
}
cd /data
输入
gcc -fpic -shared -o libgx.so gx.c
在data目录中生成libgx.so文件
cp libgx.so /usr/local/lib
输入/sbin/ldconfig
新建gxtest.c
#include<stdio.h>
int main()
{
printf("%d",gx(1222));
return 0;
}
gcc -o gxtest -lgx gxtest.c
./gxtest
返回1222,测试成功。
下载php-5.4.16源码,解压到data目录
进入/data/php-5.4.16/ext目录
输入./ext_skel --extname=gx
在ext目录中生成gx模块
进入gx目录
编辑config.m4文件
将
dnl PHP_ARG_ENABLE(gx, whether to enable gx support,
dnl Make sure that the comment is aligned:
dnl [ --enable-gx Enable gx support])
修改为
PHP_ARG_ENABLE(gx, whether to enable gx support,
dnl Make sure that the comment is aligned:
[ --enable-gx Enable gx support])
输入phpize,如果没有phpize,先yum stall php-devel
编辑php_gx.h,在PHP_FUNCTION(confirm_gx_compiled);下一行添加PHP_FUNCTION(gx);
编辑gx.c,在zend_function_entry gx_functions方法中的PHP_FE(confirm_gx_compiled,NULL)的下一行添加PHP_FE(gx,NULL)
在末尾添加代码
PHP_FUNCTION(gx)
{
long int a;
long int result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &a) == FAILURE) {
return;
}
result = gx(a);
RETURN_LONG(result);
}
输入./configure
输入make LDFLAGS=-lgx
输入make install,(安装进/usr/lib64/php/modules)
编辑php.ini
在; extension_dir = "./"下添加extension=gx.so
重启apache,systemctl restart httpd.service
php代码中调用,echo gx(1222);
以后直接覆盖libgx.so即可更新使用。