设为首页 收藏本站
查看: 548|回复: 0

[经验分享] PHP扩展生成器

[复制链接]

尚未签到

发表于 2017-3-21 08:00:26 | 显示全部楼层 |阅读模式
作者:zhanhailiang 日期:2013-02-05

第一种方法:使用PHP源码包自带的ext_skel工具。


~/public_html/php-5.3.13/ext> ./ext_skel  --extname=sample11
Creating directory sample11
Creating basic files: config.m4 config.w32 .svnignore sample11.c php_sample11.h CREDITS EXPERIMENTAL tests/001.phpt sample11.php [done].

To use your new extension, you will have to execute the following steps:
1.  $ cd ..
2.  $ vi ext/sample11/config.m4
3.  $ ./buildconf
4.  $ ./configure --[with|enable]-sample11
5.  $ make
6.  $ ./php -f ext/sample11/sample11.php
7.  $ vi ext/sample11/sample11.c
8.  $ make

Repeat steps 3-6 until you are satisfied with ext/sample11/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.


第二种方法:使用CodeGen_PECL。


/usr/local/services/php/bin> sudo ./pear install CodeGen_PECL
downloading CodeGen_PECL-1.1.3.tgz ...
Starting to download CodeGen_PECL-1.1.3.tgz (102,640 bytes)
........................done: 102,640 bytes
install ok: channel://pear.php.net/CodeGen_PECL-1.1.3
/usr/local/services/php/bin>
sudo ln -s /usr/local/services/php/bin/pecl-gen /usr/local/bin/
~/public_html/php-5.3.13/ext>
pecl-gen --extname=sample12
Strict Standards: Declaration of CodeGen_PECL_Element_Constant::docFooter() should be compatible with that of CodeGen_Element::docFooter() in /usr/local/services/php/lib/php/CodeGen/PECL/Element/Constant.php on line 341
Strict Standards: Declaration of CodeGen_PECL_Element_Resource::hCode() should be compatible with that of CodeGen_Element::hCode() in /usr/local/services/php/lib/php/CodeGen/PECL/Element/Resource.php on line 354
Strict Standards: Declaration of CodeGen_PECL_Element_Ini::docFooter() should be compatible with that of CodeGen_Element::docFooter() in /usr/local/services/php/lib/php/CodeGen/PECL/Element/Ini.php on line 443
Strict Standards: Declaration of CodeGen_PECL_Element_Logo::hCode() should be compatible with that of CodeGen_Element::hCode() in /usr/local/services/php/lib/php/CodeGen/PECL/Element/Logo.php on line 259
Strict Standards: Declaration of CodeGen_PECL_Element_Method::setCode() should be compatible with that of CodeGen_PECL_Element_Function::setCode() in /usr/local/services/php/lib/php/CodeGen/PECL/Element/Method.php on line 471
Strict Standards: Declaration of CodeGen_PECL_Element_Stream::hCode() should be compatible with that of CodeGen_Element::hCode() in /usr/local/services/php/lib/php/CodeGen/PECL/Element/Stream.php on line 239
Your extension has been created in directory ./sample12.
See ./sample12/README and/or ./sample12/INSTALL for further instructions.


注:报错“Strict Standards: Declaration of […] should be compatible with that of […] in […]”是因为PHP5.3.0+不允许子类方法签名与父类方法签名不匹配导致的,以上例第一个严格错误提示:


Strict Standards: Declaration of CodeGen_PECL_Element_Constant::docFooter() should be compatible with that of CodeGen_Element::docFooter() in /usr/local/services/php/lib/php/CodeGen/PECL/Element/Constant.php on line 341

如下对比CodeGen_PECL_Element_Constant和CodeGen_Element的docFooter方法的声明的差异:


/usr/local/services/php/lib/php/CodeGen> grep -Rn "class CodeGen_PECL_Element_Constant" .
./PECL/Element/Constant.php:39:class CodeGen_PECL_Element_Constant
/usr/local/services/php/lib/php/CodeGen> grep -Rn "class CodeGen_Element" .
./Element.php:33:abstract class CodeGen_Element
// ./PECL/Element/Constant.php
330     /**-
331      * Generate DocBook XML section block footer
332      *
333      * @access public
334      * @param  string  Extension name
335      * @return string  DocBook XML snippet
336      */

337     static function docFooter()
338     {
339         return "  </variablelist>\n";
340     }
341 }
342
343 ?>
// ./Element.php
292     /**                                                           
293      * Generate documentation footer block for all elements of this class  
294      *
295      * @access public                                             
296      * @param  string Extension name                              
297      * @return string documentation fragment                     
298      */

299     static function docFooter($name)
300     {
301         return "";
302     }                                                            
303         
304 }   
305                                                                  
306 ?>

请直接修改php.ini:


error_reporting = E_ALL & ~E_STRICT

以上只是给出了生成PHP扩展的最简单的命令,ext_skel和pecl-gen还支持多种参数生成更加丰富的扩展,请参考相关帮助文档。


~/public_html/php-5.3.13/ext> ./ext_skel --help
~/public_html/php-5.3.13/ext> pecl-gen --help
其中,pecl-gen支持从XML中导入生成扩展的强大功能,参见文档:CodeGen_PECL
- the PHP extension generator

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-352702-1-1.html 上篇帖子: php函数速查 下篇帖子: 什么是PHP FastCGI?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表