Jump to content

PHP as CGI vs Apache module


jimfog
 Share

Recommended Posts

What does it mean that PHP can run on the server either as CGI oras an Apache module?

Link to comment
Share on other sites

Apache module - runs with the priviliges that Apache has. Stuff (like database connections for example) can persist across HTTP requests until the HTTP server is restarted, resulting in better performance.CGI - runs with its own privilages (by default with those of Apache, but not necesarily), which if adjusted properly can help for better security of the server. Stuff does not persists across requests.There's also FastCGI, which combines the best of both world - PHP runs with its own privilages, and stuff can persist across HTTP requests, until the HTTP server is restarted and/or a certain time limit ("recycling" time limit) is reached.

Link to comment
Share on other sites

Apache module - runs with the priviliges that Apache has. Stuff (like database connections for example) can persist across HTTP requests until the HTTP server is restarted, resulting in better performance.CGI - runs with its own privilages (by default with those of Apache, but not necesarily), which if adjusted properly can help for better security of the server. Stuff does not persists across requests.There's also FastCGI, which combines the best of both world - PHP runs with its own privilages, and stuff can persist across HTTP requests, until the HTTP server is restarted and/or a certain time limit ("recycling" time limit) is reached.
Ok, how am i going to understand the way PHP runs on the host i have uploaded a site of mine?Can i find such info in the cPanel or do i have to run any script-containing the phpinfo() function maybe?
Link to comment
Share on other sites

CGI - runs with its own privilages (by default with those of Apache, but not necesarily), which if adjusted properly can help for better security of the server. Stuff does not persists across requests.
Please excuse me for interrupting, but I have a clarification question before the dialogue wanders off in a different direction. When you write "runs with its own privil[e]ges" in the above passage, are you referring to the CGI or the PHP interpreter or both?Maybe, if you were to clarify the relationship between the CGI and the PHP interpreter, my question would answer itself.Roddy
Link to comment
Share on other sites

Ok, how am i going to understand the way PHP runs on the host i have uploaded a site of mine?Can i find such info in the cPanel or do i have to run any script-containing the phpinfo() function maybe?
In phpinfo(), at the top somewhere, there should be "Server API" and it will have the value "CGI/FastCGI" if PHP runs on CGI or FastCGI, and something else (I think "Apache module") if PHP runs as an Apache module. Differentiating between CGI and FastCGI is a little harder unless you can know explicitly from another source... one way is to actually try to take the benefits of FastCGI and see if you can take them. If you can't, you're running on CGI for sure.What benefit to try using? MySQLi persistent connections for example.(The following is hypothetical; I haven't actually done such a test, but I'd assume it should work)Open a connection, get the stats, sleep() for a few seconds and during those seconds, open up another file that does the same thing. Print the stats after the two sleep()s are over, and see if the stats match. If they do, the connection is a persistent one, and you're therefore running on Fast CGI.
Please excuse me for interrupting, but I have a clarification question before the dialogue wanders off in a different direction. When you write "runs with its own privil[e]ges" in the above passage, are you referring to the CGI or the PHP interpreter or both?Maybe, if you were to clarify the relationship between the CGI and the PHP interpreter, my question would answer itself.Roddy
CGI is not something separate that runs PHP. CGI is a "protocol" of sorts... a very basic one, which basically goes on to say something among the lines of "The output of the program, normally viewed in a console, shall be the raw HTTP response to be delivered, headers and body as is; The input, that in a console would come from I/O devices, shall be the raw HTTP request, as received, headers and body as is".So it's not that "CGI runs PHP", it's "PHP running as a CGI compatible program". And because it's a separate program, it could potentially be launched with priviliges different from the program (Apache) that is calling it.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...