本文共 4322 字,大约阅读时间需要 14 分钟。
导读:
Here's how it works:
- IIS loads the FastCGI Process Manager (isapi_fcgi.dll) on startup.
- The FastCGI Process Manager initializes itself, creating multiple FastCGI processes (php.exe's in the Task Manager) and waits for a new connection from the Web server.
- When a client request comes in, the FastCGI Process Manager selects and opens a connection to a FastCGI process. The server sends the CGI environment variable information and standard input over to the FastCGI process.
- Then the FastCGI process completes its processing and sends the standard output and error information back to the server over the same connection.
- When the FastCGI process closes the connection, the request is complete. The FastCGI process then waits for another connection from the FastCGI Process Manager running in IIS. In normal CGI, php.exe would be terminated at this point.
In the above example, you can imagine how much slower CGI is. For every
web request PHP would need to re-parse php.ini, reload all the dll
extensions and reinitialize all data strucures. With FastCGI, all this
is done once per process startup. As an extra bonus, persistent
database connections also work.
Benchmarks
The stability of PHP in FastCGI mode is
exceptional. I have many long scripts which have problems running in
ISAPI, but work beautifully in FastCGI and CGI mode. I also tested with
apache bench. Here are my results for a test that includes a query to
Oracle, using persistent connections, simulating 5 concurrent web
client connections, using PHP 4.3.1 and IIS 5 on a W2K server (P3 800
Mhz, 256 Mb RAM) using the following command:
ab -c5 -n100 -k http://server/testoracle.php
With FastCGI:
Requests per second: 3.33 Time per request : 1.50 secs
The same query with CGI:
Requests per second: 0.44 Time per request : 11.49 secs
In other words, performance improved by 766% when using FastCGI.
This is consistent with . A stress test with 10,000 requests worked fine with no memory leaks.
Note: the time per request is longer than the requests/second would indicate because we tested concurrently with 5 threads querying at the same time. So with FastCGI, although one request completes in 0.211 seconds, because there are 5 threads, the mean time per request across all threads is 0.042 seconds. Quick Installation on IIS
I found Shane's instructions a bit confusing if you are not a guru,
so i have written this guide to help others get FastCGI working on IIS:
- Make sure you have PHP 4.3.x or later installed. Earlier versions of PHP require extra work to get FastCGI working.
- This example assumes your cgi application is located in c:/php/php.exe.
- Download and unpack isapi_fcgi.dll to c:/php/isapi_fcgi.dll.
- Create the following registry key with regedit.exe:
HKEY_LOCAL_MACHINE:Software/FASTCGI/.php
- Then add to this key the following values:
AppPath = c:/php/php.exe BindPath = php-fcgi
Alternatively, you can download and run the sample registry file . You might want to change the AppPath of the sample. - Add the application mappings extensions you want to be sent to the fastcgi dll using the IIS configuration screens. To do so:
- From the Internet Service Manager (MMC), select the Web site or the starting point directory of an application.
- Open the directory's property sheets (by right clicking and selecting properties), and then click the Home Directory, Virtual Directory, or Directory tab.
- Click the Configuration button, and then click the App Mappings tab.
- Click Add, set the file extension to .php, and in the Executable box, type: c:/php/isapi_fcgi.dll, and check the Check that file exists checkbox and save the mapping.
- Do the same for similar extensions such as .php3 or .phtml.
- Then save all changes and restart the web-server.
- To test, request for multiple web pages at the same time, and observe the processes in the Task Manager. After the web requests complete, the php.exe processes will continue running.
Personal Notes
Unlike Apache, there appears to be no way to limit the number of
requests a FastCGI process (php.exe) can handle, before restarting it.
However it appears that process restarts are automatically occurring,
as the process id's are changing slowly over time.
To detect whether FastCGI is running, check $_SERVER['FCGI_SERVER_VERSION']. It should hold something like "2.2.2 0.5.2 beta".
本文转自
转载地址:http://cwiob.baihongyu.com/