编写自己的php扩展函数来源: 发布时间:星期一, 2009年1月12日 浏览:37次 评论:0
php
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 下载 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 首先转移你 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ./ext_skel --extname=module_name module_name是你自己可以选择 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ./buildconf ./configure --enable-module_name make 下面我来演示建立my_module扩展框架 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 在php目录下 ![]() ![]() ![]() ./ext_skel --extname=my_module 得到反馈结果: Creating directory my_module Creating basic files: config.m4 Makefile.in .cvsignore my_module.c php_my_module.h tests/001.phpt my_module.php [done]. To use your ![]() 1. $ cd .. 2. $ vi ext/my_module/config.m4 3. $ ./buildconf 4. $ ./configure --[with|enable]-my_module 5. $ make 6. $ ./php -f ext/my_module/my_module.php 7. $ vi ext/my_module/my_module.c 8. $ make Repeat steps 3-6 until you are satisfied with ext/my_module/config.m4 and step 6 confirms that your module is compiled ![]() code and repeat the last two steps as often as necessary. 如果你能看懂上面 ![]() ![]() ![]() ![]() ![]() ![]() ![]() Cd my_module 首先进入my_module目录 vi config.m4 使用文本编辑器打开config.m4文件 ![]() dnl $Id$ dnl config.m4 for extension my_module dnl don't forget to call PHP_EXTENSION(my_module) dnl Comments in this file start with the ![]() dnl Remove where necessary. This file will not work dnl without editing. dnl If your extension references something external, use with: dnl PHP_ARG_WITH(my_module, for my_module support, dnl Make sure that the comment is aligned: dnl [ --with-my_module Include my_module support]) dnl Otherwise use enable: dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support, dnl Make sure that the comment is aligned: dnl [ --enable-my_module Enable my_module support]) ![]() dnl If you will not be testing anything external, like existence of dnl headers, libraries or functions in them, just uncomment the dnl following line and you are ready to go. dnl Write more examples of tests here... PHP_EXTENSION(my_module, $ext_shared) Fi 根据你自己 ![]() dnl PHP_ARG_WITH(my_module, for my_module support, dnl Make sure that the comment is aligned: dnl [ --with-my_module Include my_module support]) 修改成 PHP_ARG_WITH(my_module, for my_module support, Make sure that the comment is aligned: [ --with-my_module Include my_module support]) 或者将 dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support, dnl Make sure that the comment is aligned: dnl [ --enable-my_module Enable my_module support]) 修改成 PHP_ARG_ENABLE(my_module, whether to enable my_module support, Make sure that the comment is aligned: [ --enable-my_module Enable my_module support]) ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Vi my_module.c 将文件其中 ![]() /* Every user visible function must have an entry in my_module_functions 在文件 ![]() PHP_FUNCTION(say_hello) 保存文件退出 vi php_my_module.h 在文件中PHP_FUNCTION(confirm_my_module_compiled); ![]() ![]() PHP_FUNCTION(say_hello); 保存文件退出 退回到php ![]() ![]() ![]() ./buildconf ./configure --enable-my_module make 如果 ![]() ![]() ![]() ![]() ![]() <? 保存文件为say_hello.php 在php ![]() ./php –q say_hello.php 正常情况下会显示 hello world 表示我们 ![]() ![]() ![]() 解释 ![]() ![]() ![]() ![]() ![]() my_module.c 扩展模块 ![]() ![]() php_my_module.h 扩展模块 ![]() config.m4 配置文件 主 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 在对应 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Vi my_module.c 修改最后 ![]() ![]() PHP_FUNCTION(say_hello) 存盘退出 ![]() 退回php ![]() ![]() make 修改say_hello.php为 <? 保存退出后运行 ./php –q say_hello.php 得出结果 hello world, yorgo 表示我们这次 ![]() ![]() ![]() ![]() ![]() ![]() 这里主要解释上面修改 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() zval **yourname; 代码解释如下: zval **yourname; ![]() ![]() ![]() ZEND_NUM_ARGS ![]() 得到传递过来得参数数量 ![]() ![]() ![]() ![]() zend_get_parameters_ex(1, &yourname) 将刚刚 ![]() ![]() ![]() ![]() ![]() Z_STRVAL_PP(yourname) 处理指针指向 ![]() ![]() ![]() 0
相关文章读者评论发表评论 |