CGI,FastCGI,PHP-CGI,PHP-FPM,Spawn-FCGI
Posted toDoYourBest
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CGI,FastCGI,PHP-CGI,PHP-FPM,Spawn-FCGI相关的知识,希望对你有一定的参考价值。
CGI
- CGI, Common Gateway Interface, is a tool for HTTP server to contact with programs on other servers, which can be used into any languages with standard input, standard output and environmental variables, such as php, Perl, or Tcl.
FastCGI
- FastCGI is a kind of CGI which is long-live, which will always be running. With FastCGI, it‘ll take less time t fork(which is a problem of fork-and-execute mode in CGI). In additional, FastCGI also supports for distributed computing.
-
It is also not language related, which is an opened extension of CGI, which is used to keep CGI running in the memory. It‘s well-known that loading of CGI has been the main reason of low performance.
-
the main process of running FastCGI:
- Loading the Process Manager of FastCGI when a Web server has booted(IIS ISAPI or Apache Module)
- The Process Manager of FastCGI will initiate itself to create several CGI processes, which are used to wait for connection of Web servers.
- When requests from clients have reached the Web server, the Process Manager of FastCGI will select a CGI set up before to connect, whose environmental variables and standard input will be sent to the sub process
php-cgi
of FastCGI. - This sub process will return standard output and error info to the Web server with the same connection. Requests will be finished when it closes the connection.
- Therefore, FastCGI only set once for parsing
php.ini
, loading extensions and initiating all the data structures.
shortcuts
- Because of multi-processes, FastCGI will cost more memory than CGI, whose each process(PHP-CGI) will cost about 7Mb to 25Mb memory.
- Data from the article: Nginx 0.8x + PHP 5.2.13(FastCGI) is 10 times better than Apache(Edition 6)
- when 30k connection happens in parallel, 10 nginx processes will only cost 150Mb Mem(15Mb 10), and 64 PHP-CGI will only cost about 1280Mb(20Mb 64).
PHP-CGI
- PHP-CGI is one kind of the Process Manager of FastCGI, which is within php itself.
- The command to boot is as follow:
php-cgi -b 127.0.0.1:9000
shortcuts
- After changing
php.ini
, you should reboot PHP-CGI to make the newphp.ini
work. - When a PHP-CGI process is killed, all the PHP code will cannot run.(PHP-FPM and Spawn-FCGI do not have the same problem)
PHP-FPM(Fast-CGI Process Manager)
- PHP-FPM is another kind of the Process Manager of FastCGI, which can be downloaded here.
- It‘s actually a patch for PHP, which is used to integrate the Process Manager of FastCGI into PHP, which should be make into PHP before version 5.3.2(5.3.2以后已经集成于php中).
- PHP-FPM can be used to control sub processes of PHP-CGI:
/usr/local/php/sbin/php-fpm [options]
# options
# --start: start a fastcgi process of php
# --stop: force to kill a fastcgi process of php
# --quit: smooth to kill a fastcgi process of php
# --restart: restart a fastcgi process of php
# --reload: smooth to reload php.ini
# --logrotate: enable log files again
Spawn-FCGI
- Spawn-FCGI is a general kind of the Process Manager of FastCGI, which is one part of lighttpd.
以上是关于CGI,FastCGI,PHP-CGI,PHP-FPM,Spawn-FCGI的主要内容,如果未能解决你的问题,请参考以下文章
cgi,fastcgi,php-cgi,php-fpm 是什么
CGI与fastcgi与php-fpm与php-cgi的关系
fastcgi php-cgi与php-fpm区别和之间的关系