Differences between CGI, FastCGI, PHP-CGI, PHP-FPM, Spawn-FCGI Back


  • 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 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:

    1. Loading the Process Manager of FastCGI when a Web server has booted(IIS ISAPI or Apache Module)
    2. The Process Manager of FastCGI will initiate itself to create several CGI processes, which are used to wait for connection of Web servers.
    3. 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.
    4. 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.


  • Because of multi-processes, FastCGI will cost more memory than CGI, whose each process(PHP-CGI) will cost about 7Mb to 25Mb memory.


  • 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


  • After changing php.ini, you should reboot PHP-CGI to make the new php.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 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.
  • 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 is a general kind of the Process Manager of FastCGI, which is one part of lighttpd.
Empty Comments
Sign in GitHub

As the plugin is integrated with a code management system like GitLab or GitHub, you may have to auth with your account before leaving comments around this article.

Notice: This plugin has used Cookie to store your token with an expiration.