您的位置:首页 > 编程语言 > PHP开发

PHP扩展开发之动态加载so模块与静态重编译PHP(下)

2016-10-20 11:51 561 查看
1.在/usr/local/src/php-7.0.9/ext目录下创建my_dynamic.def

[root@bogon ext]$ vi my_dynamic.def
string my_dynamic()每行一个函数,行尾无分号


2.生成框架

[root@bogon ext]$ ./ext_skel --proto=my_dynamic.def --extname=my_dynamic --skel=skeleton/
[root@bogon ext]# cd ..
[root@bogon php-7.0.9]# vi ext/my_dynamic/config.m4
删注释后
PHP_ARG_ENABLE(my_dynamic, whether to enable my_dynamic support,
dnl Make sure that the comment is aligned:
[  --enable-my_dynamic           Enable my_dynamic support])


后面的操作均在php源码目录/usr/local/src/php-7.0.9中进行

3.执行./buildconf 重新构建configure

[root@bogon php-7.0.9]#  ./buildconf --force
[root@bogon php-7.0.9]#  ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --enable-mysqlnd  --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd=/usr/local/gd --with-png-dir=/usr/lib --with-jpeg-dir=/usr/lib --with-freetype-dir=/usr/lib --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization  --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl  --enable-ctype --with-my_dynamic=/usr/local/src/php-7.0.9/ext/my_dynamic


最后一句:

-with-*=/usr/local/src/php-7.0.9/ext/my_dynamic

*与config.m4中 [ –with-my_dynamic Include my_dynamic support])名称一致,



以上目录根据自身情况填写,笔者PHP的环境安装详见:http://blog.csdn.net/xujunabc999/article/details/52588145

4.编译:

[root@bogon php-7.0.9]# make
[root@bogon php-7.0.9]# make install




5.测试是否编译成功

[root@bogon php-7.0.9]#  ./sapi/cli/php -f ext/my_dynamic/my_dynamic.php




6.编写my_dynamic.c中的my_dynamic函数

查找PHP_FUNCTION(my_dynamic),修改为:

PHP_FUNCTION(my_dynamic)
{
php_printf("The Best or Nothing\n");
RETURN_TRUE;
}


7.保存后再次编译

[root@bogon php-7.0.9]# make install


8.验证是否成功

在/ext//my_dynamic下编写test.php测试文件

[root@bogon php-7.0.9]# /usr/local/php7/bin/php ./ext//my_dynamic/test.php




至此,my_dynamic模块已完全编译到PHP中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php 扩展 函数
相关文章推荐