SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Php + Cgi-bin

  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php + Cgi-bin

    Hi,

    A few years back I dipped into Perl using CGI but that was ages ago now and since I have become comfortable is using PHP. I have used PHP as a Apache Module and not with CGI. Seeing as i have never used PHP and CGI together am after some advice here as I have searched around the web and there are a few reviews regarding PHP and CGI but some contradict each other.

    Is their any benefits for me to move to use PHP with CGI and if so what are these benefits?

    Are there any specific quick tutorials on how to use PHP and CGI together just to refresh my memory from my perl experience?

    Regards
    p_h_p

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think there is no reason for you not to switch to PHP: it is more popular, hence has better support, and greater community.

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by p_h_p View Post
    Is their any benefits for me to move to use PHP with CGI and if so what are these benefits?
    If you're running a shared host, there are some security issues with apache+mod_php, since all the virtual hosts will be sharing the same user. If you run PHP as CGI, you can isolate each virtual host completely from each other. You can also run different versions of PHP -- something which isn't possible, using mod_php. That said, CGI is rarely used, since mod_php is a lot faster, and offers some additional features (Interacting with apache).

  4. #4
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like the thing you're misunderstanding though is that PHP as CGI, as far as syntax and features are concerned, is pretty much exactly the same. In PERL as CGI there's a lot of manual parsing you have to do but PHP is nothing like this in any form.

    So really it doesn't matter which you use, but as mentioned above the apache module is faster.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  5. #5
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies.

    So from the posts above and from what i have read around the web PHP + CGI is more secure than mod_php. I am going to be developing a large site in PHP including security so if PHP and CGI is the safest option I will choose this.

    I have a good knowledge of coding mod_php but have never coded with CGI and PHP. As devbanana said the differences in the two coding techniques is not huge but are there any quick tutorials on this that anyone could recommend? - I understand that for php you do not have a seperate cgi-bin dir as you do with perl. So I am assuming most of mod_php code will still work in a PHP-CGI environment, just an odd few coding differences. - Am I correct on this assumption?

    Cheers
    p_h_p
    Last edited by p_h_p; May 16, 2007 at 05:20.

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Off Topic:

    Don't know if this adds to the thread really, but I understand you can run both PHP4 and PHP5 on the same server running one as cgi.
    (Trachtenbergs "Upgrading to PHP5" O'Rielly)

  7. #7
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by p_h_p View Post
    So from the posts above and from what i have read around the web PHP + CGI is more secure than mod_php. I am going to be developing a large site in PHP including security so if PHP and CGI is the safest option I will choose this.
    The safest would be to not develop the application -- then no body can hack it.

    Seriously though -- The vast majority of all PHP sites run under mod_php. CGI is rarely used. If your application is not going to run on a shared host, I don't think it makes a difference, security wise.

  8. #8
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, there are no coding differences. There are just some Apache-specific functions that you cannot use under PHP CGI, but are rarely used anyway.

    Honestly I'd just recommend using mod PHP.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  9. #9
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers evryone for helping me out.

    I am just going to use mod_php as moving to php + cgi seems unecessary from the posts above and from what I have researched.

    regards
    p_h_p

  10. #10
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Kansas City, MO
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use PHP + FCGI (fast-cgi is really fast) and have it spawned as a seperate process (usually running on a UNIX Domain socket or TCP/IP socket) ... it self manages it's instances / child processes and this also allows you to restart PHP without touching your httpd.

    Still allows multiple PHP instances per user, each with their own config, etc.

    You just have to compile PHP --with-fastcgi and start php with the -b argument (binds to a local socket)


Bookmarks

Posting Permissions

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