FastCGI PHP pros and cons comparison

Source: Internet
Author: User
Keywords PHP pros and cons FastCGI
Tags an application application application development applications apps connect development file

PHP fastcgi makes all your PHP apps run through MOD_FASTCI instead of mod_phpsusexec. FastCGI applications are fast because they are durable and stable. You do not have to start and initialize each request. This makes application development possible, otherwise the CGI paradigm is impractical (such as a large script, or an application that needs to connect to a single or multiple databases).

Benefits

PHP scripts run more quickly (3 to 30 times times). The PHP interpreter is loaded into memory without having to read it from memory every time it is needed, greatly enhancing the performance of the site that relies on the script to run. Fewer system resources are needed. Because the server does not load the PHP interpreter every time you need it, you can increase the speed of the site to a high rate without increasing the CPU burden. There is no need to make any changes to the existing code. Everything is available for PHP fastcgi

Potential problems

For all subdirectories (/home/username/public_html/php.ini) you have only one available php.ini file. This is necessary to optimize the site code. If you need multiple php.ini files to accommodate different scripting needs, you can disable PHP's fast CGI in any subdirectory, and the rest will continue to work. If you need to do this please contact support. Any upgrades you make to the PHP environment (such as php.ini file changes) are delayed for several minutes. This is because your php.ini file has been loaded into memory for faster speeds, rather than being re-read from memory every time you need it.

How FASTCGI Works

1. Load fastcgi Process Manager (IIS ISAPI or http://www.aliyun.com/zixun/aggregation/14417.html ">apache Module) on Web server Startup"

2, the FASTCGI process manager itself initializes, initiates multiple CGI interpreter processes (visible multiple php-cgi) and waits for a connection from the Web server.

3. When a client request arrives at the Web server, the FASTCGI process manager selects and connects to a CGI interpreter. WEB server sends CGI environment variables and standard input to the fastcgi subprocess php-cgi.

4. The fastcgi child process completes processing and returns standard output and error information from the same connection to the Web Server. When the fastcgi child process closes the connection, the request is processed. The fastcgi process then waits and processes the next connection from the FASTCGI process Manager, which is running in the Web server. In CGI mode, php-cgi exits.

In the above scenario, you can imagine how slow CGI is usually. Each Web request PHP must reparse php.ini, reload all extensions, and reinitialize all data structures. With fastcgi, all of these occur only once when the process is started. An additional benefit is that persistent database connections (persistent DB connection) can work.

The shortage of fastcgi

Because it is a multiple process, it consumes more server memory than CGI multithreading, and the PHP-CGI interpreter consumes 7 to 25 megabytes per process, multiplying this number by 50 or 100 is a large amount of memory.

The Nginx 0.8.46+php 5.2.14 (FastCGI) server consumes 150M of memory (Nginx) with 10 15m*10=150m processes on 30,000 concurrent connections, and 64 php-cgi processes that open consume 1280M memory (20m*64= 1280M), combined with the memory consumed by the system itself, consumes less than 2GB memory. If the server memory is small, you can simply turn on 25 php-cgi processes so that the total amount of memory consumed by php-cgi is 500M.

Related Article

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.