PHP Handlers PHP Handlers is an Apache module contain libraries that is used by Apache to communicate with the PHP interpreter, PHP interpreter is an application that executes PHP code and process it to be sent as static format (for example html). It's basically used by Apache to handle requests for PHP files.
There are different types of PHP handlers :
1. DSO (Dynamic Shared Object) DSO or mod_PHP is the oldest and the fastest PHP handler available. It essentially makes PHP a part of Apache by having the Apache server interpret the PHP code itself through use of an Apache module known as mod_PHP.
mod_PHP is fast because runs directly in the same process as Apache server. But, it will use the same user that your Apache process runs as (www-data or apache). This means that all work on files will be done as the Apache user which therefore must have permissions to all of your files.
2. CGI (Common Gateway Interface) CGI is the fallback in most servers when mod_PHP is not available. Instead of running the PHP code within Apache it is now run as it’s own CGI process, that is, in a program outside of your Apache server.
Unlike mod_PHP however CGI has the ability to see the PHP as another user (presumably the user that owns the files) using another Apache module known as suexec. For performance CGI is not nearly as fast as mod_PHP and requires more CPU time. It is however still soft on memory usage which may be a benefit to some users.
3. suPHP (Single User PHP) suPHP or mod_suphp runs PHP outside of the Apache script as CGI. Unlike CGI however it will run the scripts as a user other than the Apache user (presumably the user that owns the files). This means that if you are using a CMS you will be able to upload files from within your web application using suPHP. In addition, because your PHP is being run as a different user any vulnerability in your site can be restricted to only the files of your website thereby providing substantial security benefits particularly on servers that run multiple websites.
suPHP is slow and requires quite a bit of CPU to process all the files. In addition, as it must process the file each and every time it is called, suPHP cannot use any OPCode caching such as APC or memcached resulting in even higher CPU usage by your application. If you are running on a low-end VPS or other server with an application such as WordPress this configuration can easily push you passed any CPU limits you might have whenever traffic starts to climb.
4. FastCGI FastCGI offers the security benefits of suPHP by executing files as the owner of the file. Unlike suPHP however it keeps open a session for the file when the processing is done resulting in significant memory use but also allowing for the use of OPCode caching such as APC or memcached. If you do have the memory for it however FastCGI is arguably the fastest handler even in comparison with mod_PHP
If you have the memory for it there really isn’t any reason not to run FastCGI in this day and age. In cases where memory is restricted however the choice may come down to security vs performance.
5. PHP-FPM (FastCGI Process Manager) FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features (mostly) useful for heavy-loaded sites. The PHP-FPM implementation of FastCGI provides process management, emergency restarts, and IP address restriction.
This is a variant of PHP that will run in the background as a daemon, listening for CGI requests. Output is logged to /var/log/php-fpm.log. Most options are set in the configuration file. The configuration file is /etc/php-fpm.conf. By default, php-fpm will respond to CGI requests listening on localhost http port 9000. Therefore php-fpm expects your webserver to forward all requests for '.php' files to port 9000 and you should edit your webserver configuration file appropriately.
Reference https://www.chriswiegman.com/2011/10/fastcgi-vs-suPHP-vs-cgi-vs-mod_PHP-dso/ . https://www.inmotionhosting.com/support/website/php/choosing-the-best-php-handler .