4

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!

LGB
  • 728
  • 1
  • 9
  • 20
  • Suggest to your customers that they could use PEAR::Mail for a few bucks or keep using mail() with your zend core modifications for a couple of thousands. That might make them change their mind :) – mobius Nov 14 '11 at 14:04
  • Using things like PEAR is the last I want: as I use chroot-ed environment, I would need deploy these things into homes of every user separately. That's why I would love mail() if I can modify it in a nice way to use other strategy than calling sendmail binary. To be honest it's a bit odd for me: as with windows there is the SMTP based implementation but with UNIX the sendmail way. Why can't PHP provide SMTP on UNIX too? It would be much easier to modify for me at least then :) – LGB Nov 14 '11 at 15:40

2 Answers2

3

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

Good luck.

cu Roman

  • Well, thanks, but my question was about to have more detailed information about the "how", not a general howto, or API reference, which still to need learn as a whole before I can find the answer out :) – LGB Nov 15 '11 at 15:37
2

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
halfdan
  • 33,545
  • 8
  • 78
  • 87
  • auto_prepend_file does not help me, as I need C code (even low level, as I want extend CGI SAPI to handle network communication with SCGI: no, FastCGI is something I can't use here), not PHP. .user.ini is a good point though thanks for the advice, however I am not sure if it works, since I need parse an INI file which is outside of the directory structure/path where user homes are. As far as I know, PHP (from 5.3.0) only parse these files if it detects one in the path where my script (which will be executed) is. – LGB Nov 14 '11 at 13:57
  • To be more specific: I don't want user to be able to specify PHP settings, but that I give them extra settings (which cannot be changed by them) on per-user base, outside of the directory structure used by user homes (to be sure that they can't manipulate it - at least not directly). – LGB Nov 14 '11 at 16:49