PHP Extension 扩展开发_PHP_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > PHP > PHP Extension 扩展开发

PHP Extension 扩展开发

 2013/5/19 14:50:52  netkiller.github.com  程序员俱乐部  我要评论(0)
  • 摘要:第23章PHPExtension扩展开发目录1.ExtensionExample2.PHP_MINFO_FUNCTION1.ExtensionExample创建一个扩展只需要下面几个步骤#cdphp-5.4.14/ext/#./ext_skel--extname=netkiller#cdnetkiller#/srv/php-5.4.8/bin/phpize#./configure--enable-netkiller--with-php-config=/srv/php-5.4.8/bin/php
  • 标签:PHP Ten 开发

?

?

class="title">第?23?章?PHP Extension 扩展开发

目录

1. Extension Example
2. PHP_MINFO_FUNCTION

1.?Extension Example

创建一个扩展只需要下面几个步骤

		
# cd php-5.4.14/ext/
# ./ext_skel --extname=netkiller
# cd netkiller
# /srv/php-5.4.8/bin/phpize
# ./configure --enable-netkiller --with-php-config=/srv/php-5.4.8/bin/php-config
# make
# make install
		
		

下面我们开始分部讲解,首先创建一个扩展。

		
./ext_skel --extname=netkiller
Creating directory netkiller
Creating basic files: config.m4 config.w32 .cvsignore netkiller.c php_netkiller.h CREDITS EXPERIMENTAL tests/001.phpt netkiller.php [done].

To use your new extension, you will have to execute the following steps:

1.  $ cd ..
2.  $ vi ext/netkiller/config.m4
3.  $ ./buildconf
4.  $ ./configure --[with|enable]-netkiller
5.  $ make
6.  $ ./php -f ext/netkiller/netkiller.php
7.  $ vi ext/netkiller/netkiller.c
8.  $ make

Repeat steps 3-6 until you are satisfied with ext/netkiller/config.m4 and
step 6 confirms that your module is compiled into PHP. Then, start writing
code and repeat the last two steps as often as necessary.
		
		

编辑config.m4

		
# vim netkiller/config.m4
PHP_ARG_ENABLE(netkiller, whether to enable netkiller support,
Make sure that the comment is aligned:
[  --enable-netkiller           Enable netkiller support])
		
		

去掉上面三行前的dnl, dnl 表示注释

		
# cat config.m4 | grep -v 'dnl'

PHP_ARG_ENABLE(netkiller, whether to enable netkiller support,
Make sure that the comment is aligned:
[  --enable-netkiller           Enable netkiller support])

if test "$PHP_netkiller" != "no"; then

  PHP_NEW_EXTENSION(netkiller, netkiller.c, $ext_shared)
fi
		
		

执行 phpize

		
# cd netkiller
# /srv/php-5.4.8/bin/phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525

# ./configure --enable-netkiller --with-php-config=/srv/php-5.4.8/bin/php-config
# make
# make install

# ls modules/
netkiller.la  netkiller.so
		
		

创建 ini 文件

		
cat >> /srv/php/etc/conf.d/netkiller.ini <<PHP
extension=netkiller.so
PHP
		
		

确认扩展看装成功

		
# /srv/php/bin/php -f netkiller.php
Functions available in the test extension:
confirm_netkiller_compiled

Congratulations! You have successfully modified ext/netkiller/config.m4. Module netkiller is now compiled into PHP.

# /srv/php-5.4.8/bin/php -m | grep netkiller
netkiller
		
		

创建 php 测试程序

		
vim test.php

<?php
echo confirm_netkiller_compiled('netkiller');
phpinfo();
		
		

输出结果

		
Congratulations! You have successfully modified ext/netkiller/config.m4. Module netkiller is now compiled into PHP.

netkiller
---------------------------
netkiller support	enabled
上一篇: wamp setup 下一篇: php位运算符注意事项
发表评论
用户名: 匿名