如何编写可以修改 PHP 解释器内部结构的自定义 PHP 扩展?
是否可以编写一个 PHP 扩展(UNIX、CGI SAPI),我可以:
- 重新定义 PHP 函数的实现(如 mail()):许多 PHP 软件使用标准的 mail() 函数 - 我无法更改它,因为客户想要使用它,故事结束... - 但我需要重写它,因为在 chroot() 环境中不可能生成 sendmail 进程 - 我需要套接字级通信,这也不是标准 SMTP 顺便说一句)
- ”停止”PHP 解释器(所以我可以为我的oen做其他事情)在进行PHP脚本的实际解析/执行之前,但在完成所有初始化工作(扩展加载、ini文件解析等)之后,我们将其称为“php脚本执行之前” hook”左右:)
- 强制解析一个INI文件(路径由我生成/定义),它可以重新定义之前设置的所有设置(如果有的话)
目前我已经修改了PHP源代码本身,但是这很丑陋,也可能很危险,如果我可以将其作为 PHP 扩展来实现,那就太好了,至少使用看起来像 PHP 扩展的东西:),这样我就不需要修改“核心 PHP”.. !
非常感谢
Is it possible to write a PHP extension (UNIX, CGI SAPI) where I can:
- 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)
- "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 :)
- 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)
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" ...
Thanks a lot in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
网络上有很多 Howto 文章和参考文献解释了基本的 Hello World 及其他内容。
祝你好运。
铜
罗马
There are quite some Howto articles and references on the web explaining basic Hello World and beyond.
Good luck.
cu
Roman
关于第 2 点和第 3 点:
auto_prepend_file
的形式存在。Regarding points 2 and 3:
auto_prepend_file
.