PHP modes

When creating a website you may face quite a controversial matter of what operation mode of PHP interpreter program choose as VDS webservers sustain several of them. In the article we will try to reveal their fors and againsts.

1. Mod_php or PHP as Apache Module

In this mode, Apache settings are configured by applying mod_php module that is onwards integrated in each webserver underway process. This mode is considered to be the most convenient. This is the most applicable choice for small web projects with not many visitors.


  • Scripts run at high speed
  • Cache customizing will do to increase efficiency


  • There exists only one global php.ini file that you can customize, but not individual for each of your websites. Some parameters (but a very few of them) you may redefine in .htaccess file;
  • The method is not safe enough as it has Apache privileges, being executed on his behalf. Only mod_ruin may run as separate users though PHP under it is executed as a module;
  • No matter what request a user made, this module will be loaded in every running webserver process. As a result the server and its resources may be overloaded;
  • A webserver crash becomes one of script errors;
  • It becomes much more difficult to reveal the user running third party software via script;
  • Multithread Apache running (MPM Worker) may not support some PHP modules.

2. CGI mode of PHP

PHP and other scripts with CGI as a handler are running via php-cgi interpreter at this mode on. If your website mostly deals with static data and seldom execute PHP, this mode is the best solution for you. The fact that PHP is executed only if requested saves RAM greatly. But such way of PHP running is much longer as PHP interpreter is downloaded into RAM.


  • Any user of the system is able to run CGI handler within Suexec applications;
  • Each user may customize PHP configuration pursuant to his needs;
  • RAM is used to run CGI only when needed;
  • As PHP is a separate process under this mode, there exists minimal chance that scripts will cause a crash of the webserver;
  • Different clients may run different versions of PHP.


  • Low level of productivity.
  • Header command is limited in creating authorization of PHP. The limitation is caused by script inability to receive several variables of the server.

3. SuPHP

This mode presuppose running of PHP interpreter as CGI module.


  • You can always detect who runs this or that PHP script as owners run them;
  • If you are not the owner of the script, you will not run it;
  • At loading files on the server, the user conveys his rights to them.


  • This mode has higher load on the processor that CGI, though still quite little;
  • Cache options such as APC, XCache etc., are not available.

4. Mod_fastcgi or PHP in FastCGI mode

The features of FastCGI mode make it the happy medium between mod_php and CGI modes. It incorporates all CGI’s virtues though does not have its weak points. Having FastCGI run, RAM is consumed by handler process running constantly. Thus there is no need to execute a new process for each request as CGI does. Response speed is equal to that of mod_php.

There are little more merits such as:

  • Cache customizing will increase productivity;
  • Only the owner of the script can run it;
  • FastCGI has a variable that is aimed to diminish the risk of pending by defining the number of server requests before rebooting the interpreter.

However, there are still some disadvantages:

  • Permanently running processor php_cgi load RAM very much whatever requests are available.
  • There are less RAM that on mod_php and static content is spreading without accessing PHP interpreter.

5. Where to look for your current PHP mode?

1) You can use phpinfo() function

Create a file (e.g. file.php) on your server with the following code:


Now save the changes and in a browser open this file. You will receive a page containing the information of PHP version and parameters. Among the parameters you can find Server API that defines current PHP mode. Here is an example:


2)   You can use php_sapi_name()

Create a file (e.g. file.php) on your server with the following code:

$sapi = php_sapi_name();
echo $sapi;

Now save the changes and in a browser open this file. You will receive the page that displays your current PHP mode name. Here is an example:


Also Read


Quick Navigation

Client Login



Remember Me