简体   繁体   English

如何编写可以修改PHP解释器内部的自定义PHP扩展?

[英]How can I write a custom PHP extension which can modify the internals of the PHP interpreter?

Is it possible to write a PHP extension (UNIX, CGI SAPI) where I can: 是否可以编写PHP扩展(UNIX,CGI SAPI),我可以:

  • redefine the implementation of a PHP function (like with mail(): many PHP softwares uses the standard mail() function - I can't change that since customers want to use that, end of story ... - but I need rewrite it, as in chroot()'ed environment it's not possible to spawn a sendmail process - I need socket level communication which is not standard SMTP either btw) 重新定义PHP函数的实现(比如mail():许多PHP软件使用标准的mail()函数 - 我无法改变,因为客户想要使用它,故事结束...... - 但我需要重写它,如在chroot()'环境中,不可能产生sendmail进程 - 我需要套接字级通信,这不是标准SMTP或btw)
  • "stop" PHP interpreter (so I can do other things for my oen) before doing the actual parse/execute of the PHP script, but after doing ALL of the initialization work (extension loading, ini file parsing, etc), let's call it "before php script execution hook" or so :) 在执行PHP脚本的实际解析/执行之前,“停止”PHP解释器(所以我可以为我的其他事做),但是在完成所有初始化工作(扩展加载,ini文件解析等)之后,让我们调用它“在PHP脚本执行钩子之前”左右:)
  • force parsing an INI file (path is generated/definied by me) which can redefine all of the setting which was set before (if it was at all) 强制解析INI文件(由我生成/定义路径),它可以重新定义之前设置的所有设置(如果它完全是)

Currently I've modified the PHP source itself, but that's ugly and maybe dangerous as well, it would be nice if I can do this as a PHP extension, well, at least with something looks like a PHP extension :) so I don't need to modify the "core PHP" ... 目前我已经修改了PHP源代码本身,但这很丑陋,也许很危险,如果我可以将它作为PHP扩展来做,那就好了,好吧,至少看起来像PHP扩展:)所以我不喜欢需要修改“核心PHP”......

Thanks a lot in advance! 非常感谢提前!

There are quite some Howto articles and references on the web explaining basic Hello World and beyond. 网上有很多Howto文章和参考资料,解释了基本的Hello World及其他内容。

Good luck. 祝好运。

cu Roman 罗马

Regarding points 2 and 3: 关于第2点和第3点:

  • A "before php script execution hook" already exists in form of the php.ini option auto_prepend_file . php.ini选项auto_prepend_file形式中已存在“之前的php脚本执行挂钩”。
  • You can use .user.ini to override specific ini-options 您可以使用.user.ini覆盖特定的ini-options

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM