73

There are few different php "wrappers"(?). What are differences between them? Tried to google some, but cant seem to find informations. (mod-php is not googleable).

Why might I choose one over another?

141

The questions is a little bit strange, it's not clear if you're asking only for PHP or your question is more general.

I will give you a brief overview from the PHP side.

First, the two protocols:

  • CGI scripts is a way how to run a server side script when a HTTP request comes; this has nothing to do with PHP

  • FastCGI is a "better CGI" - CGI is known to be slow, Fast CGI is a different approach with much faster results; this has also nothing to do with PHP.

Now the PHP related things:

  • mod_php is running a PHP as Apache module - that is PHP request is run under Apache process with everything that goes with it - Apache processes are defined by Apache configuration, PHP is run with Apache permission etc.

  • PHP-FPM is PHP's FastCGI implementation; PHP-FPM runs as a standalone FastCGI server and Apache connects to the server using Apache's module, usually mod_fcgid or mod_fastcgi; I personally think this is much better than running as mod_php, but it depends on your requirements and is also a little more complex; in this configuration, permission, processes related stuff & everything is run under PHP configuration, PHP user etc. & Apache connects to PHP as to a server; in this configuration it is also possible to have pool of PHP servers and to have PHP server on physically different machine than Apache. They say this is almost as fast as using Apache's module and there are benefits of better control over PHP configuration.

  • SuPHP - this was mostly used to address some problems of mod_php related to permissions; with mod_php PHP scripts are run under the Apache user/group; mod_suphp can run the scripts in different user; I never used it, PHP-FPM now should be much better choice

So, basically:

  • CGI, Fast-CGI are protocols; CGI is slow, Fast-CGI is much faster
  • mod_php (with underscore) and PHP-FPM are two basic ways how to run PHP
  • mod_SuPHP is similar to mod_php but can change the user/group that the process runs under
  • Maybe I will clarify what inspired me for this question. I just got a VPS with a ISPConfig panel (Opensource panel to admin pages). There I can chose a PHP version for server/side. And those are listed there. So basically it seems that chosing PHP-FPM choses FastCGI with additional "wrappers"? – Gacek Nov 20 '14 at 11:22
  • 12
    I do not know what ISPConfig panel really uses, but PHP run as PHP-FPM means, that PHP will start it's own built-in FastCGI server and will listen for requests through FastCGI protocol. HTTP server will be receiving requests from internet, handling them as usually and in case a page needs to be run using PHP, request will be handed over FastCGI protocol to PHP and the result would be sent back to browser. Think of that as HTTP server standing between browser and PHP (PHP-FPM FastCGI) server. PHP-FPM is an implementation of FastCGI protocol. – Aleš Krajník Nov 21 '14 at 0:10
  • @AlešKrajník thanks for that elaborate explanation. Well, I've been trying to run php as seperate user/group. So I started with Su-exec and hit a dead end and then a couple of people recommended php-fpm which you have explaned. However, am still confused about modules mog_cgi, mod_cgid, mod_fastcgi, mod_fcgi and how these work with php-fpm. Also I read in another tutorial they were using mod_fcgid and mod_proxy_fcgi. How struggling to understand how all the pieces come together. – David Okwii Nov 30 '16 at 7:13
  • 1
    @landed PHP-FPM binary is part of every PHP distribution since 5.3.3 or 5.4.0 (check this: php-fpm.org), for that specific PHP version. – Aleš Krajník May 17 '17 at 6:13
  • 2
    php-fpm is all about removing initialization costs. php-fpm pre-starts several php processes, ready to process requests, and have them sleep until requests come in - which means it can respond much faster than traditional cgi, because php is already running when requests come, as opposed to traditional CGI, where a new php process is started for each request, also php-fpm doesn't shut down the php process after processing requests, but keep reusing the same processes. - with 0 overhead of starting and stopping processes, php-fpm responds much faster. starting & stopping processes takes time. – hanshenrik Jul 22 '17 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.