Choosing a web server operating mode based on personal experience: CGI or FastCGI

This article will be useful to those people who already have their own site, or who are planning to open it. The article will be especially interesting for ambitious webmasters who feel that the finest hour of their project is just around the corner and want to prepare for the influx of page visitors.

PHP as Apache module (mod_php)

A module for the Apache web server that allows it to handle all PHP requests without using third party modules.

Benefits:

  • High performance;
  • It is possible to inject PHP variables into .htaccess.

Disadvantages:

  • individual users on a server running mod_php cannot make changes unless they have access rights to all the processes it works with. In other words, the rights of the web server must be granted to all users on the server;
  • Low security level, since it is impossible to determine the user who launched a specific process (all processes are executed anonymously under the apache user);
  • Errors in scripts can paralyze the entire server;
  • Web servers with mod_php are slow to process static data.

 

PHP in CGI and FastCGI mode

PHP CGI is one of the first scripts for processing php scripts by the server using the mod_cgi module. It is now rarely used and is considered obsolete.

In this mode, each php request is executed by a separate process. This degrades site performance and takes longer to process scripts.

The development of the CGI (Common Gateway Interface) technology is the FastCGI interface.
When creating a FastCGI script, we took into account the slow speed of processing scripts in CGI, therefore, in this mode, cyclical processing of several requests by one process is used. FastCGI is a memory savings by reducing the number of running processes.

Benefits:

  • The user has the rights to execute all scripts on his www-domain;
  • Security (each request is executed under a separate user, running an unsafe php script will not affect the files of other users who are on the same server);
  • Each user on the server can choose a personal version of PHP;
  • No server crashes if there are errors in scripts;
  • Processing the rules of the .htaccess configuration file, which is supported by popular CMS (WordPress, Joomla, 1C-Bitrix, etc.).

Disadvantages:

  • Slightly lower performance compared to the Apache module;
  • Slow processing of static data without linking to the Nginx web server.

 

PHP in FPM mode

FPM (FastCGI Process Manager) is an alternative implementation of PHP FastCGI. PHP FPM is the only module that is suitable for a pure Nginx web server.

  • How PHP FPM works:
  • Fast processing of static data;
  • No need for an Apache web server;
  • Less RAM consumption.

Disadvantages:

There is no support for the .htaccess configuration file. This requires self-configuration of similar rules on the side of the Nginx web server.

Add a Comment

Your email address will not be published. Required fields are marked *