You get a bonus - 1 coin for daily activity. Now you have 1 coin

Advantages and disadvantages of PHP FastCGI and mod_php (php as apache or FastCGI module)

Lecture



The main differences between assemblies.

Security:

  • mod_php:
    php_value directives will work in .htaccess, 777 permissions are allowed (more precisely, necessary) (which is extremely unsafe), folders and files are created not on behalf of the user, but on behalf of apache (this is one of the drawbacks: delete such files and folders without the help of administrators You just can not). With this option, 95% of wap scripts will work without prior configuration.
  • PHP FastCGI:
    php_value directives (error 500 will appear) are forbidden in .htaccess, rights 777 are not allowed (contrary to misconceptions, it is worth noting that 755 rights are more than enough to write to the folder, and 666 files, or at least, 666), and also execution of scripts occurs on behalf of the user. With this build, free scripts without preliminary settings will refuse to work (error 500 will appear).

Speed:

  • mod_php:
    launched by the web server with each new request. Sometimes the launch of an application takes a significant part of the time, and it often takes more time to start up than the useful work that it does further. It can also be noted that errors in scripts can lead to the inoperability of the entire web server.
  • PHP FastCGI:
    can be implemented as a daemon, i.e. it can itself be a server. The FastCGI application is always running, so it doesn’t waste time starting, it only needs to do useful work. Errors in the scripts do not lead to the inoperability of the entire server.

It is important to note that with 300-500 connections, there will be no tangible difference in server load, be it fcgi or mod_php. But with a value of 1000 compounds, FastCGI will prevail.

Let us summarize the results of comparing the php FastCGI and php Apache module (mod_php), highlighting the advantages and disadvantages out of the above:

Php as apache module

In this case, PHP uses the apache mod_php web server module.

Virtues

  • The highest speed of the scripts, compared with other methods (for large numbers of requests).
  • Simplicity of work, the server itself handles scripts.
  • General configuration file for all scripts (php.ini).
  • Ability to set PHP configuration variables in the web server configuration file or using the .htaccess file

disadvantages

  • All scripts run with the rights that the web server works with, thereby if there is a need to write to any directory, you need to give access rights to it to everyone, i.e. low security.
  • In the case of launching third-party applications with scripts (for example, mailing lists), it is not possible to identify the user who started the process.
  • Excessive load on the web server. Apache, busy processing scripts, may slowly give away other static data.
  • Errors in the scripts can lead to the inoperability of the entire web server.

Php like fastcgi

In this case, the Apache mod_fastcgi module is used, the scripts are transmitted by its means as input to the PHP interpreter.

Virtues

  • All scripts are executed with the rights of the user - the owner of the www-domain.
  • Ability to customize PHP for each user.
  • Less memory usage than apache module.
  • Errors in the scripts do not lead to the fall of the web server, in contrast to PHP mode as an apache module.
  • Due to the caching of some intermediate data, the script is not interpreted each time it is executed and it achieves a higher speed compared to PHP as CGI.

disadvantages

  • The extra user process (php-cgi) is in memory after the first call to the process.

Thus, the use of FastCGI is more secure, both in terms of access rights, and in terms of the presence of errors in the work of extraneous scripts, and in a more economical and fast way of operating PHP scripts. mod_php, in turn, has a slight increase in speed with a large (in thousands of connections) load on the site.


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Running server side scripts using PHP as an example (LAMP)

Terms: Running server side scripts using PHP as an example (LAMP)