PHP handlers

PHP handlers are a link between a webserver(Apache HTTP Server/nginx) and the PHP libraries. PHP handlers enable a webserver to load the PHP library in a certain manner and execute the PHP code and return the output to the webserver.

There are five main PHP handlers.
1) PHP DSO
2) CGI
3) FastCGI
4) suPHP
5) PHP-FPM

 

1) PHP DSO

  • Feature provided by the module libphpX.so.
  • libphpX.so is the default PHP handler that comes with the PHP installation. It can run only PHP scripts.
  • It runs under the UID of webserver. So files or directories created or modified by PHP will not be accessible to any other user.
  • Does not work with suEXEC.
  • Insecure.
  • PHP Accelerators will work with it since it keeps worker processes alive.
  • It keeps persistent connections open that can be recalled by the same PHP process.
  • Low CPU usage. Low memory usage.
  • http://php.net/manual/en/install.unix.apache2.php

 

2) CGI

 

3) FastCGI

  • Feature provided by the module mod_fcgid.so.
  • FastCGI is a variation of CGI. It comes from the Apache HTTP Server project as an additional download. It can run both PHP and CGI scripts.
  • It runs under the UID of webserver. So files or directories created or modified by PHP will not be accessible to any other user.
  • Works with suEXEC.
  • Secure only with suEXEC.
  • PHP Accelerators will work with it since it keeps worker processes alive.
  • It keeps persistent connections open that can be recalled by the same PHP process. Takes more memory because it keeps PHP sessions opened in the background in memory.
  • Low CPU usage. High memory usage.
  • http://httpd.apache.org/mod_fcgid/

 

4) suPHP

  • Feature provided by the module mod_suphp.so.
  • mod_suphp.so is a third-party module. It can run both PHP and CGI scripts.
    NOTE: It is no longer actively developed and is officially supported only upto Apache HTTP Server v2.2.x.
    TIP: Read here if you want to use suPHP with higher versions of Apache HTTP Server.
  • It can run under the UID of user executing PHP scripts. There are no file permission issues.
  • Does not need suEXEC.
  • Secure.
  • PHP Accelerators will not work with it since it does not keep worker processes alive.
  • It is non-persistent. It starts a new PHP process upon every request. Takes more CPU resources due to process creation.
  • High CPU usage. Low memory usage.
  • To change PHP directives we will have to use php.ini instead of .htaccess file.
  • http://suphp.org

 

5) PHP-FPM