简体   繁体   中英

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:

  • 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!

There are quite some Howto articles and references on the web explaining basic Hello World and beyond.

Good luck.

cu Roman

Regarding points 2 and 3:

  • A "before php script execution hook" already exists in form of the php.ini option auto_prepend_file .
  • You can use .user.ini to override specific ini-options

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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