PHP handlers Compared

PHP handlers Compared

In plain English: PHP handlers are Apache modules that interpret and run PHP code. Using right PHP handler on your website can have a huge impact on the overall performance.

In cPanel you can have different PHP versions with different handlers for each website. To list available PHP handlers in WHM, navigate to Software » MultiPHP Manager

Available PHP handlers in WHM:

CGIDSOsuPHPFastCGILSAPI
processes owned by:script owner
(only w/ suEXEC)
nobodyscript ownerscript ownerscript owner
CPU usage:CPU-intensivelow CPU usageCPU-intensivelow CPU usagelow CPU usage
RAM usage:lowlowlowhighlow
speed:slowslowfastfastfast
security:lowmediumhighhighhigh
Opcode cache supported:XYESXXYES
.htaccess or php.iniphp.ini.htaccessphp.iniphp.ini.htaccess

CGI (Common Gateway Interface)

Back in the old days, php and perl scripts were installed in the cgi-bin directory and when that directory was accessed the server runs the script and sends the output to the user’s browser. This days however the cgi-bin directory is no longer required to process server/side code because most servers are configured to run any PHP/Perl script as CGI code. Thts why today CGI (mod_cgi) is rarely used and is considered to be slow and less secure when compared to other PHP handlers.

CGI (mod_cgi) processes are by default run as the nobody user, which makes it hard to understand which processes are owned by which user. Other notable features of CGI are:

  • .htaccess directives are not used, instead, you have to use php.ini file
  • Uses more CPU but less RAM, because it creates a new process for each request.
  • Does not support PHP Opcode cache methods.

DSO (Dynamic Shared Object)

Unlike CGI, DSO (mod_php) is not by default enabled on cPanel servers but can be installed via EasyApache. DSO creates a new web server (httpd) process whenever PHP script is executed, then lets Apache interpret the code and spawn child processes when needed.

Some notable features of DSO PHP handler are:

  • supports some Apache directives in .htaccess file and the main php.ini file.
  • Does not use a lot of CPU because it does not immediately terminate processes.
  • Supports Opcode cache

suPHP (Single User PHP)

suPHP (mod_suphp) which is no longer maintained and largely replaced by PHP-FPM. works pretty much like the CGI handler but is considered to be more secure because scripts are always executed with the permissions of their owner.

  • Apache directives can be added using php.ini files.
  • CPU intensive because it creates a new process for each request – same as CGI.
  • suPHP cannot use any OPCode caching such as APC or memcached.

FastCGI

FastCGI (mod_fcgid) is a newer and more improved version of CGI. It keeps PHP scripts in memory so it doesn’t have to start a new PHP process every time the script is executed.

  • Supports custom php.ini files within the accounts.
  • Uses more RAM because it stores PHP scripts in memory.
  • If you want to be able to use directives inside htaccess – you’ll need to allowoverride them.

LSAPI (LiteSpeed Server Application Programming Interface)

LSAPI is an drop-in replacement for Apache web server and is designed specifically for seamless, optimized communication between LiteSpeed Web Server and third party web applications. On cPanel servers that run CloudLinux it can be accessed from the WHM under Plugins » LiteSpeed Web Server.

  • Change PHP configurations via web server configuration or .htaccess files
  • Lowest CPU and RAM usage, up to 50% greater performance then mod_php.
  • Supports various Opcache methods.

PHP-FPM (FastCGI Process Manager)

FPM isn’t really a handler but it’s a daemon that works along side FastCGI. It uses pools to manage processes more efficiently and uses less memory.

High-traffic websites can benefit from using PHP-FPM, but the only initial down side it that it needs a bit tweaking to get the most out of PHP-FPM.

  • Supports custom php.ini files within the accounts.
  • Relatively light on memory because it uses pools for process management.
  • Provides process management, emergency restarts, and IP address restriction.

Special Note for WordPress Users

Functions that require file uploads will NOT work unless PHP is loaded as a CGI module, meaning that WordPress works only with suPHP or FastCGI handlers. This will ensure they are uploaded with the correct ownership & permissions.

Written by
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Categories