Knowledgebase

PHP modes

There exist several operating modes of PHP interpreter programs on VDS webserver, and the matter of choice is quite debatable. Each variant has its pros and cons, which we are going to consider onward in the article.

Contents

  1. PHP as Apache Module (mod_php)
  2. PHP in CGI mode
  3. SuPHP
  4. PHP in FastCGI mode (mod_fastcgi)
  5. How to find out your current PHP mode?

1. PHP as Apache Module (mod_php)

To work in this mode, mod_php module is applied to Apache settings, and then is integrated in each process running on a webserver. In most cases, this is the most appropriate choice. A small site with a small number of visitors will work more quickly than any other variant.

Advantages:
  • High speed of script running;
  • One can increase productivity by means of cache customizing.
Disadvantages:
  • One cannot customize an individual php.ini for each website. Configuration is possible only in the global php.ini and narrow number of parameters may be reloaded (redefined) in htaccess;
  • All scripts are executed as Apache and thus have its privilege level in the system that on safety grounds is not a sound method. The exception is mod_ruin, which runs PHP as a module, but executes scripts as different users;
  • Module is loaded in all running processes of a webserver regardless of the data type requested by a client. This creates extra load on a server resources;
  • Script errors may involve a webserver crash;
  • If one can run third party software through a script, it will take up lots of time and energy to find out the user that has run it;
  • There are problems with compatibility of some modules with multithread Apache running (MPM Worker).

2. PHP in CGI mode

If this mode is on, php-cgi interpreter starts up to run PHP and other scripts that have CGI installed as a handler.

This option is worth using when a website comprises mostly static content and needs to process PHP from time to time. This makes it possible to save greatly on RAM using by means of running PHP interpreter only if needed. On the other hand, each PHP script will be executed longer thus every time there will be a need to download PHP interpreter in RAM.

Advantages:
  • One can run CGI handler as any existing user in the system. Suexec applications is used for that;
  • One can make individual PHP configuration according to the needs of each user;
  • RAM is used for CGI running only if there is clear need;
  • Chance of a webserver crash because of scripts is reduced to a minimum by means of PHP working as a separate process;
  • One can run different PHP versions for different clients.
Disadvantages:
  • Low productivity;
  • Limits in creating PHP authorization using Header command. They are connected with the fact that script does not receive some server variables.

3. SuPHP

When using SuPHP, PHP interpreter is also running as CGI module.

Advantages:
  • PHP scripts are run by their owner, and owing to this one can always see who has run a script;
  • Any script, which is not of current user’s possession, will not run;
  • Files, loaded to the server through a website, have rights of the user who loaded them.
Disadvantages:
  • Processor load is a little bit higher than that of CGI.
  • One cannot use cache options (APC, XCache, etc.)

4. PHP in FastCGI mode (mod_fastcgi)

According to its properties, FastCGI is the golden mean between mod_php and CGI modes. It does not have CGI’s drawbacks, but has its advantages. With FastCGI running, there is a constantly running handler process in the server RAM. This excludes the need to run a new process at each request, as it is with CGI. FastCGI’s speed of response in similar to that of mod_php.

Some more advantages should be mentioned:

  • One can increase productivity by means of cache customizing;
  • Scripts are run by the owning user;
  • To decrease risk of pending, a variable that defines the number of requests under service before the interpreter’s rebooting was introduced to FastCGI.

The following disadvantages can be singled out:

  • RAM is highly loaded because of constantly working processor (php_cgi) regardless of any requests available. At the same time, it is much smaller than with mod_php, this distribution of static content goes without accessing PHP interpreter.

5. How to find out your current PHP mode?

Way #1. Phpinfo() function

  • On your hosting create a file, e.g. test.php, and add the following code into it:
    <?php
    phpinfo();
    ?>
  • Save changes and open this file in a browser. As a result, you will see a page with information about version and parameters of PHP, among which there will be Server API parameter, whose value shows current PHP mode.

php_modes_1.jpg

At the picture above you can see an example of Server API value at PHP running in FastCGI mode.

Way #2. php_sapi_name()

  • On your hosting create a file, e.x. test.php, and add the following code into it:
    <?php
    $sapi = php_sapi_name();
    echo $sapi;
    ?>
  • Save changes, and then open the file in a browser. As a result, you will see a page showing the name of the current PHP mode. The example below shows the result for FastCGI.

php_modes_2.jpg

Looking for cheap USA VPS hosting? We offer VPS servers with different types of virtualization and management options at reasonable prices.
Also Read
Can I add PTR record? (Views: 60)

Language:

Quick Navigation

Client Login

Email

Password

Remember Me

Search