Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
- Join Date
- Oct 2011
is it true PHP is faster than CGI
while working with both CGI and PHP i found out from internet that PHP is faster than CGI script. When i tried them, i saw that PHP scripts can be executed slightly faster than CGI script. for your information, both of CGI and PHP script that i tested have the same functionality which are to execute external C program.
i wrote my CGi script using unix shell. even though it seem to me that php is faster but im not sure why it is faster than CGI. anyone here has ideas about this.
It would depend on many factors so it would be a bit simplistic to say that it is always faster. Using Apache as an example, an Apache module such as modphp would be faster than a PHP CGI script in general but I don't know how fastCGI would stack up.Should you be sitting wondering,
Which Batman is the best,
There's only one true answer my friend,
It's Adam Bloody West!
The Fifth Continent
mod_php would benefit, if it doesnt have to call external programs.
One can also speed up mod_php even more by the use of an accelerator such as Alternative PHP Cache (APC)
But as elija already said: There are a lot of variables and it depends on your usecase.You must always face the curtain with a bow.
And note that coding skill in each environment matters. A clumsily coded solution for the faster environment may be outrun by a gracefully coded one in the slower environment.
- Join Date
- Mar 2012
I know that Facebook compiles all their php into native binaries with HipHop for php to save a lot of resources (more RAM than CPU), but I tested a simple hello world as being faster in php than calling a cgi program. I don't know if I was using fastCGI. I assume real software doing substantial work would benefit, but if HipHop isn't too much trouble you can benchmark both. HipHop is free and open sourced.
- Join Date
- Dec 2009
The general reason that people say php is faster than cgi is because it avoids the expensive fork/exec. This is also true for servlets run inside tomcat or some other process.
Normally, when a CGI request comes in, apache must call fork to make a copy of itself. The child of the fork then calls exec to convert itself to the cgi program (/bin/sh or whatever in the case of a shell script).
mod_php is faster because it executes the php inside the apache with no fork.
All that being said, unless you are scaling up to handle a lot of concurrent users, the cgi program will be just fine.