webbcite
10-04-2001, 02:00 PM
I have PHP4 installed on my server. I now have several different reasons that I need to have PHP run in CGI mode. So my question(s) is:
If I recompile in CGI mode, do I loose the normal PHP web server mode? What exactly does running is CGI mode do for me? How hard is it to recompile with CGI mode enabled?
Any help is appreciated...
MattR
10-04-2001, 02:19 PM
CGI mode means, more or less, that Apache (or your server of choice) will pass all PHP files to a PHP executable file instead of handling the PHP document itself.
Simplisticly Apache will do this:
gets a request for bob.php
realizes it is a php file, then calls:
/usr/bin/php bob.php
captures the output
gives the HTML output to the user
webbcite
10-04-2001, 02:26 PM
So, is it one or the other? Are there any performance hits or any reason that I would not want to run in CGI mode?
Thanks
ffeingol
10-04-2001, 02:33 PM
Well it is a performance hit. Every time Apache wants to call php it has to start the php process. I can't tell you how much of a performance hit though. There are also some security issues.
Why do you need to run php as a cgi?
Frank
alchiba
10-04-2001, 02:36 PM
Yes, there is a performance penalty for running PHP in CGI mode because your server will have to locate, load and run the PHP executable each time Apache calls for it. It involves more layers of your system to use it this way, is why. However you likely won't notice it too much unless you have a fairly high hit-count on your PHP pages.
It seems to me it's possible to set up your box so that both flavors of PHP (DSO and CGI) can co-exist. One version would work through Apache as a loadable module while the other would be invoked as a CGI. You'd need to use distinct filename extensions, however. This might be worth exploring unless someone shoots down the idea.
freakysid
10-04-2001, 07:29 PM
Yes you can do this. I have done this. I compiled php --with-apxs (as an apache dso libphp4.so). To be honest - I don't know whether that compile compiled the php binary as well into /usr/local/bin because I went back and recompiled php but this time without the apxs option in the configure command.
I have done this because for some strange reason, I cannot get the mod_php version to workwith db3 files (or db2 for that matter) - I keep getting db3 driver initialization errors when I run my php scripts through php as an apache module. But when I run those particular scripts through the php binary - no problem. (Redhat 7.1 problem - don't have this problem on my local Redhat 7.0 development box).
As someone else mentioned, you will need to use a different extention between the two types of file (cgi versus php) and set up your document types in httpd.conf to handle both. (ie AddType .cgi for php scripts to be run as cgi).