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
- 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
- Feature provided by the modules mod_cgi.so & mod_cgid.so.
- mod_cgi.so & mod_cgid.so comes with Apache HTTP Server installation. It can run both PHP and CGI scripts.
mod_cgi.so is used with single-threaded MPM.
mod_cgid.so is used with multi-threaded MPM. - 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.
- Insecure even with suEXEC.
- PHP Accelerators will not work with it since it does not keep worker processes alive.
- It is non-persistent. It must start a PHP process upon every request. Takes more CPU resources due to process creation.
- High CPU usage. Low memory usage.
- http://httpd.apache.org/docs/2.4/mod/mod_cgi.html
- http://httpd.apache.org/docs/2.4/mod/mod_cgid.html
- 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/
- 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
- Feature provided by the binary php-fpm.
- php-fpm is an alternative PHP FastCGI implementation. It is FPM or Fast Processing Manager enabled and comes with the PHP installation. It can run both PHP and CGI scripts.
- 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 work with it since it keeps worker processes alive.
- It keeps persistent connections open that can be recalled by the same PHP process. Ability to gracefully stop and start PHP workers without losing any queries. This allows gradually updating the configuration and binary without losing any queries.
- Low CPU usage. Low memory usage.
- http://php.net/manual/en/install.unix.apache2.php
- http://php.net/manual/en/install.fpm.php