Comparison between ISAPI and FastCGI in PHP

Source: Internet
Author: User
Tags sapi
Comparison between ISAPI and FastCGI in PHP: comparison between ISAPI and FastCGI in PHP

Http://www.cnblogs.com/huangye-dream/p/3560722.html

1. CGI (Common Gateway Interface/Common Gateway Interface) is generally an executable program, such as an EXE file, and each WEB server occupies a different process, generally, a CGI program can only process one user request. In this way, when the number of user requests is very large, it will occupy a lot of system resources, such as memory, CPU time, etc., resulting in low efficiency.

2. ISAPI (Internet Server Application Program Interface) is a set of WEB service-oriented API interfaces provided by Microsoft. it can implement all the functions provided by CGI and is expanded on this basis, for example, filter application interfaces are provided. Most ISAPI applications are used as DLL dynamic libraries and can be executed after being requested by users. they will not disappear immediately after processing a user request, instead, it continues to reside in the memory and waits for other user input to be processed. In addition, the isapi dll application is in the same process as the WEB server, and the efficiency is significantly higher than that of CGI.

3. FastCGI is an open CGI extension of the Scalable Architecture. its main behavior is to keep the CGI interpreter process in the memory and thus achieve high performance. The repeated loading of the traditional CGI interpreter is the main cause of low CGI performance. if the CGI interpreter is kept in the memory and is scheduled by the FastCGI Process Manager, it can provide good performance and scalability.

PHP is run in ISAPI mode. The biggest drawback of this method is poor stability. When PHP fails, the Apache process also dies.

Advantages of running PHP in FastCGI mode:

First, Apache will not be destroyed when PHP errors occur, but PHP's own processes will be destroyed (but FastCGI will immediately restart a new PHP process to replace the failed process ).

Second, FastCGI runs PHP in better performance than ISAPI.

Finally, you can run PHP5 and PHP4 simultaneously.

Some disadvantages of FastCGI mode:

FastCGI is more suitable for servers in the production environment, but it is not suitable for development machines. When Zend Studio is used to debug a program, FastCGI considers that the PHP process times out and returns error 500 on the page.

Starting from version 4.3.0, PHP provides support for a new type of SAPI (Server Application Programming Interface, the Server Application Programming port). The name is CLI, which indicates Command Line Interface, that is, Command Line Interface. As the name suggests, this SAPI module is mainly used as a PHP development shell application. There are many differences between cli sapi and other SAPI modules. It is worth mentioning that CLI and CGI are different SAPIs, although there are many common behaviors between them.

Cli sapi was first released with PHP 4.2.0, but it is still an experimental version. you need to add the-enable-cli parameter when running./configure. Since PHP 4.3.0, cli sapi has become a formal module. the-enable-cli parameter must be set to on by default. you can also use the parameter-disable-cli to block it.

Starting from PHP 4.3.0, the name, location, and existence of the CLI/CGI binary execution file vary depending on the installation of PHP on the system. By default, when you run make, both CGI and CLI are compiled and placed in the sapi/cgi/PHP and sapi/cli/php directories of the php source file directory. Note that both files are named php. What happens during the make install process depends on the configuration line. If you select an SAPI module, such as apxs, or use the-disable-cgi parameter, during the make install process, CLI will be copied to {PREFIX}/bin/php, unless CGI has been placed in that location. Therefore, for example, if the configuration line contains-with-apxs, CLI will be copied to {PREFIX}/bin/php during the make install process. To cancel the installation of the CGI execution file, run make install-cli after make install. Alternatively, you can add the-disable-cgi parameter in the configuration line.

The following are the significant differences between cli sapi and other SAPI modules:

* Unlike cgi sapi, its output does not contain any header information. Although cgi sapi provides a method to cancel the HTTP header information, there is no similar method in cli sapi to enable the output of HTTP header information. CLI starts in quiet mode by default, but to ensure compatibility, The-q and-no-header parameters are retained for backward compatibility, so that the old CGI script can be used. At runtime, the working directory is not changed to the current directory of the script (you can use the-C and-no-chdir parameters to be compatible with CGI mode ). When an error occurs, the error message of plain text is output (not in HTML format ).

* Cli sapi forcibly overwrites some settings in php. ini, because these settings are meaningless in the Shell environment.

  1. Nginx + php-fpm implementation principle and problem record
  2. Connect () php-cgi.sock failed (2: No such file or directory) troubleshooting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.