C++编写PHP扩展

来源:互联网 发布:deactivate python 编辑:程序博客网 时间:2024/04/20 03:30
http://devzone.zend.com/node/view/id/1021
http://devzone.zend.com/node/view/id/1022
http://devzone.zend.com/node/view/id/1023
http://devzone.zend.com/node/view/id/1024

进入php5/ext目录,用ext_skel --extname=modulename生成一个模板。
进入php5/ext/modulename/,打开config.m4,改写成
PHP_ARG_ENABLE(picen, whether to enable picen support,
[  --enable-picen           Enable picen support])

PHP_ARG_WITH(picen, whether to with picen support,
[  --with-picen           with  support])

if test "$PHP_!MODULENAME!" != "no"; then
  PHP_REQUIRE_CXX()
  PHP_SUBST(!MODULENAME!_SHARED_LIBADD)
  PHP_ADD_LIBRARY(stdc++,"",!MODULENAME!_SHARED_LIBADD)
  PHP_NEW_EXTENSION(!MODULENAME!, !MODULENAME!.cpp, $ext_shared)
fi
将!MODULENAME!替换为你的模块名。
打开你的cpp文件,将#include改为
extern "C"
{
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
}
将下面的ZEND_GET_MODULE改为
extern "C"
{
#ifdef COMPILE_DL_!MODULENAME!
ZEND_GET_MODULE(!MODULENAME!)
#endif
}
phpize生成一个配置脚本。./configure生成一个Makefile文件。make命令就可以编译了,编译好的在modules文件夹里面。用sudo make install可以将其拷贝到php5的extensions目录中。