Problem
FastCGI incomplete advanced Guide (PHP version, Windows platform)
Solution
I. What is FastCGI?
FastCGI is a CGI open extension in a language-independent and scalable architecture. Its main behavior is to maintain the CGI interpreter process in the memory and thus achieve high performance. As we all know, repeated loading of the 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, scalability, Fail-Over features, and so on.
Official site of FastCGI is at [url = http://www.fastcgi.com/? httphttp://www.fastcgi.com#/url]
FastCGI works as follows:
1. When the Web Server is started, load the FastCGI Process Manager (iis isapi or Apache Module );
2. FastCGI Process Manager initializes itself, starts Multiple CGI interpreter processes (multiple php-cgi.exe in the Task Manager), 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 the cgienvironment variable and standard input to php-cgi.exe.
4. After the FastCGI sub-process completes processing, the standard output and error messages are returned from the same connection to the Web Server. When the FastCGI sub-process closes the connection, the request processing is complete. The FastCGI sub-process then waits for and processes the next connection from the FastCGI Process Manager (running in WebServer. In the normal cgimode, php-cgi.exe exits.
In the above cases, you can imagine how slow CGI is. Every Web Request PHP must re-Parse php. ini, re-load all dll extensions, and initialize all data structures. With FastCGI, all of these occur only once when the process starts. An additional benefit is that Persistent database connection can work.
2. Why use FastCGI instead of multi-thread CGI interpreter?
This may be due to multiple considerations, such:
1. You cannot use the multi-threaded CGI interpreter on windows platform in any way. Whether it is iis isapi or APACHE Module, they will always crash after a period of running. Strange? But this is indeed the case!
Of course, you may also be able to use the multi-thread CGI interpreter in a stable manner. However, you may find that web pages sometimes encounter errors and you cannot find the cause in any case, the probability of such errors is greatly reduced when FastCGI is used. I don't know why. I think the CGI interpreter of an independent address space may be a little more stable than the shared address space.
2. Performance! Performance? Is it possible that FastCGI is faster than the multi-thread CGI interpreter? However, sometimes this is the case. Only by testing your website can you draw a conclusion. I think it is difficult to explain the reason, but I have some information that Zend, In the Zend WinEnabler era, also suggested using FastCGI on Windows platforms rather than IIS ISAPI or Apache Module, however, Zend is no longer using this product.
Iii. Reasons for not using FastCGI
1 Gbit/s multi-path consumes more memory than multi-thread. The php-cgi.exe interpreter consumes 7 to 25 Mbit/s of memory per process. Multiply this number by 50 or 100.
2. Performance. Sometimes the multi-thread CGI interpreter is faster, and sometimes it is stable.
3. CGI? It sounds pretty earthy, huh, huh
Iv. IIS FastCGI configuration method
1. First, make sure that you have correctly installed PHP 4.3.x and the updated version. Earlier versions of PHP are not supported by FastCGI by default. If you want to work in earlier versions, you need to recompile it. Suppose PHP is installed in c: PHP, And the executable file supporting fastfcgi.exe is php-cgi.exe.
Note: We recommend that you disable cgi. force_redirect in Php. ini, enable fastcgi. impersonate, and enable cgi. rfc2616_header.
2. Download [url = Hangzhou (not required in this directory, but convenient description here ).
3rd, use regedit.exe to create the following registry key:
HKEY_LOCAL_MACHINE: SoftwareFASTCGI. php (required)
4. Create the following key values under this item:
String type: AppPath; Value: c: phpphp-cgi.exe (required)
String type: BindPath; Value: php-fcgi (required)
The following are optional configuration key values:
DWORD type: StartServers. The number of interpreters started by default at startup. The default value is 5.
DWORD type: MaxServers. the maximum number of interpreters. The default value is 25.
DWORD type: IncrementServers. The number of increments when the interpreter is insufficient. The default value is 2.
DWORD type: Timeout, incremental interpreter (beyond the number of StartServers) survival time, default 600 (seconds)
DWORD type: ThreadPoolSize, thread pool size, valid only under IIS, default 10
DWORD type: Impersonate, which is valid only for IIS. If it is set to 1, use the IIS security flag. If it is set to 0, disable this feature. Do not close it unless you are not worried about security issues. Default Value: 1
DWORD type: MaxPostData, Post data pre-read Byte limit, default 0
DWORD type: BypassAuth, which is valid only for IIS. If it is set to 1 and isapi_fcgi.dll is configured as IIS Filter, and IIS is configured to use BASIC Authentication, all Authentication requests are forced to use IIS Anonymous Users. This option aims to allow scripts to implement their own security mechanisms. Default Value: 0
BINARY type: CustomVars, additional environment variable values, new lines separated, Null ended
5. If it is IIS6, add a Web Service Extension pointing to c: phpisapi_fcgi.dll and allow. The maximum number of working processes in the application pool must be 1.
6. Add the extended ing relationship of the application:
1) In Internet Information Service Manager, select the root directory of the website or application.
2) Open the directory properties page (right-click and select "properties"), and then select "main directory ".
3) Click "Configure" and select the "ing" Tab.
4 ). click "add... ", set the executable file to c: phpisapi_fcgi.dll, and the extension. php, be sure to select "check whether the file exists", and then "OK" to save the settings.
5). Also add support for. php3 or. phtml extensions (optional ).
6). Save the settings and restart IIS.
In the 7th test, multiple web pages are requested at the same time. Check the progress in the task manager. After the page is complete, the php-cgi.exe process continues to run and does not exit.
V. Apache configuration method
1. First, make sure that you have correctly installed PHP 4.3.x and the updated version. Earlier versions of PHP are not supported by FastCGI by default. If you want to work in earlier versions, you need to recompile it. Suppose PHP is installed in c: PHP, And the executable file supporting fastfcgi.exe is php-cgi.exe.
Note: We recommend that you enable cgi. force_redirect in Php. ini, disable fastcgi. impersonate, and disable cgi. rfc2616_headers.
2. Download the Modules directory in [url = Modules 2. x.
3. Make sure Apache 2.x can run PHP normally in CGI Mode. Httpd. conf contains the following lines:
ScriptAlias/php/"c:/php /"
Action application/x-httpd-php "/php/php-cgi.exe"
SetEnv PHPRC "C:/php"
AddType application/x-httpd-php. php
4. Add the following in httpd. conf:
LoadModule fastcgi_module modules/mod_fastcgi-2.4.2-AP20.dll
# Note: Here-processes 3 indicates to start three php-cgi.exe processes,
# For detailed FastCgiServer parameters, see the FastCGI document.
FastCgiServer "c:/php/php-cgi.exe"-processes 3
5. Restart Apache. The test is the same as above.
Vi. Advanced Configuration
Imagine a scenario where your server runs Apache 2 and IIS 6 at the same time, and both Web servers run php applications. There are three possibilities:
A. php is installed using iis isapi and apache module, and runs in multiple threads. This is irrelevant to FastCGI.
B. One server uses FastCGI and the other uses multithreading. This operation is normal.
C. Both use the FastCGI method, which is often abnormal. Generally:
The progress (terrible ).
Why? I think it is probably because the author of the above two things (iis isapi and apache module) has never thought about using them with the other party. Think about it. If Apache 2 and IIS 6can use a batch of php-cgi.exe interpreters, there will be no memory waste or scheduling problems.
Research and tests have proved that this idea is feasible. However, because Shane Caraveo does not use the fastcgiservice feature in ISAPI dll, iisis responsible for starting and managing php-cgi.exe, and then configuring Apache to use these iismanaged php-cgi.exe processes.
Configuration method:
1. Configure IIS FastCGI as follows.
2. Configure Apache FastCGI in the preceding five steps, and add the following in httpd. conf:
LoadModule fastcgi_module modules/mod_fastcgi-2.4.2-AP20.dll
# Use the external FastCGI server. For more information, see the FastCGI document.
FastCgiExternalServer "c:/php/php-cgi.exe"-socket "php-fcgi"
Note: The value after-socket must be HKEY_LOCAL_MACHINE: success.
Note: In this configuration, the php-cgi.exe process is only managed by the FastCGI Process Manager in IIS. The busy request of apachedoes not allow fastcgi.exe in iisto dispatch more php-cgi.exe processes. Therefore, when FastCGI is configured in IIS, The StartServers value should be large enough to avoid insufficient php interpreters. If IIS is disabled, Apache cannot find the Php interpreter.
The following problem occurs: in php. ini, how should cgi. force_redirect, fastcgi. impersonate, and cgi. rfc2616_headers be set? Let's think about this ...... Haha
Another question that can be encountered is that iisis very idle, and after a while, php-cgi.exe started by iishas exited, apache cannot explain Php. What should I do? At this time, you can initialize the iis, and php-cgi.exe will get up again, dizzy. We recommend that you use the process pool management of IIS 6 to disable "Idle timeout" in the application pool, in the application pool ID, set the running account to be consistent with the Apache service startup account.
Netizen's suggestion:
Add to favorites ......
Netizen's suggestion:
Added to favorites
However, I often use FastCGI to disable it. Several machines perform the same test. I don't know why.
Netizen's suggestion:
Official Website: [url = http://www.fastcgi.com/dist/] http://www.fastcgi.com/dist/#/url]
The version has been upgraded to 2.4.6, but the author cannot. This article should be old.
[Url = require.
In Windows, there are two ways to make PHP work in Apache 2.0.x. One is to use CGI executable programs, and the other is to use the DLL of the Apache module.
From a certain point of view, the PHP4 installed using the apache module has better security and better execution efficiency and speed than the CGI Mode.
Q: Can I use fastcgi for PHP installed using the apache module, that is, the two are loaded using the apache module, and the installation runs normally, but I don't know what the difference is between the two?
FastCGI's Apache module has some problems. For example, the process may be broken down and cannot be killed after the failure, resulting in instability. Fortunately, there is a FCGID solution that won't let FCGI go to the last path ^
Http://fastcgi.coremail.cn/index.cn.htm
[]
Netizen's suggestion:
Useful
Netizen's suggestion:
Mark
Netizen's suggestion:
Take it away. [img] http://www.111cn.cn/bbs/images/smilies/default/lol.gif#/img]
Netizen's suggestion:
Good!
Netizen's suggestion:
Nice ...... that is, apache model is better than FCGI .......... [Img] http://www.111cn.cn/bbs/images/smilies/default/33.gif#/img] [img] Quit
Netizen's suggestion:
Building occupancy Learning