php---第一个扩展开发

来源:互联网 发布:淘宝一件代发怎么付款 编辑:程序博客网 时间:2024/05/16 03:05

下载php源码 http://php.net/downloads.php
1.编译php

cd /home/php5.6.22./configure --prefix=/usr/local/phptest/ --enable-debug --enable-maintainer-zts '--enable-fpm' '--with-config-file-path=/usr/local/phptest/etc'make && make install

2.利用php自带的扩展模板生成器生成模板

cd /home/php5.6.22/ext/[root@iZ23v4z44uqZ ext]# ./ext_skel./ext_skel --extname=module [--proto=file] [--stubs=file] [--xml[=file]]           [--skel=dir] [--full-xml] [--no-help]  --extname=module   module is the name of your extension  --proto=file       file contains prototypes of functions to create  --stubs=file       generate only function stubs in file  --xml              generate xml documentation to be added to phpdoc-svn  --skel=dir         path to the skeleton directory  --full-xml         generate xml documentation for a self-contained extension                     (not yet implemented)  --no-help          don't try to be nice and create comments in the code                     and helper functions to test if the module compiled[root@iZ23v4z44uqZ ext]# ./ext_skel --extname=xing2233Creating directory xing2233Creating basic files: config.m4 config.w32 .gitignore xing2233.c php_xing2233.h CREDITS EXPERIMENTAL tests/001.phpt xing2233.php [done].To use your new extension, you will have to execute the following steps:1.  $ cd ..2.  $ vi ext/xing2233/config.m43.  $ ./buildconf4.  $ ./configure --[with|enable]-xing22335.  $ make6.  $ ./sapi/cli/php -f ext/xing2233/xing2233.php7.  $ vi ext/xing2233/xing2233.c8.  $ makeRepeat steps 3-6 until you are satisfied with ext/xing2233/config.m4 andstep 6 confirms that your module is compiled into PHP. Then, start writingcode and repeat the last two steps as often as necessary.[root@iZ23v4z44uqZ ext]#[root@iZ23v4z44uqZ ext]# cd xing2233/[root@iZ23v4z44uqZ xing2233]# vi config.m4#修改config.m4,去掉下面几行前面的dnlPHP_ARG_ENABLE(xing2233, whether to enable xing2233 support,Make sure that the comment is aligned:[  --enable-xing2233           Enable xing2233 support])PHP_SUBST(XING2233_SHARED_LIBADD)#配置php环境[root@iZ23v4z44uqZ xing2233]# /usr/local/phptest/bin/phpizeConfiguring for:PHP Api Version:         20131106Zend Module Api No:      20131226Zend Extension Api No:   220131226#编译和安装扩展[root@iZ23v4z44uqZ xing2233]# ./configure --with-php-config=/usr/local/phptest/bin/php-config[root@iZ23v4z44uqZ xing2233]# make && make installInstalling shared extensions:     /usr/local/phptest/lib/php/extensions/debug-zts-20131226/[root@iZ23v4z44uqZ xing2233]# ll /usr/local/phptest/lib/php/extensions/debug-zts-20131226/total 1276-rwxr-xr-x 1 root root 830986 Jun  2 11:51 opcache.a-rwxr-xr-x 1 root root 445603 Jun  2 11:51 opcache.so-rwxr-xr-x 1 root root  28225 Jun  2 12:03 xing2233.so#php配置文件中增加扩展[root@iZ23v4z44uqZ xing2233]# cd /home/php5.6.22[root@iZ23v4z44uqZ xing2233]# cp  php.ini-development /usr/local/phptest/etc/php.ini[root@iZ23v4z44uqZ xing2233]# vi /usr/local/php/etc/php.ini[xing2233]extension=/usr/local/phptest/lib/php/extensions/debug-zts-20131226/xing2233.so#察看是否加载了[root@iZ23v4z44uqZ phptest]# /usr/local/phptest/bin/php -mtokenizerxing2233xmlxmlreaderxmlwriter
原创粉丝点击