Find the answer to your Linux question:
Results 1 to 6 of 6
hey guys, 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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    34

    is it true PHP is faster than CGI


    hey guys,
    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.

  2. #2
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,475
    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.
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    Conkybots: Interactive plugins for your Conkys!

  3. #3
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,348
    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.

  4. #4
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    664
    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.

  5. #5
    Just Joined!
    Join Date
    Mar 2012
    Posts
    1
    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.

  6. #6
    Just Joined!
    Join Date
    Dec 2009
    Location
    California
    Posts
    98
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •