博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Robust and High Performance PHP with IIS: Using FastCGI | PHP Everywhere
阅读量:2400 次
发布时间:2019-05-10

本文共 4322 字,大约阅读时间需要 14 分钟。

导读:

Here's how it works:

  1. IIS loads the FastCGI Process Manager (isapi_fcgi.dll) on startup.
  2. 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.
  3. 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.
  4. Then the FastCGI process completes its
    processing and sends the standard output and error information back to
    the server over the same connection.
  5. 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:

  1. Make sure you have PHP 4.3.x or later installed. Earlier versions of PHP require extra work to get FastCGI working.

  2. This example assumes your cgi application is located in c:/php/php.exe.

  3. Download and unpack isapi_fcgi.dll to c:/php/isapi_fcgi.dll.

  4. Create the following registry key with regedit.exe:
    HKEY_LOCAL_MACHINE:Software/FASTCGI/.php
  5. 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.
  6. Add the application mappings extensions you want to be sent to the fastcgi dll using the IIS configuration screens. To do so:
    1. From the
      Internet Service Manager (MMC), select the Web site or the starting point directory of an application.
    2. Open the directory's property sheets (by right clicking and
      selecting properties), and then click the Home Directory, Virtual
      Directory, or Directory tab.
    3. Click the Configuration button, and then click the App Mappings tab.
    4. 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.
    5. Do the same for similar extensions such as .php3 or .phtml.
    6. Then save all changes and restart the web-server.

  7. 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/

你可能感兴趣的文章
谷词在线字典
查看>>
zlc158
查看>>
dbanotes
查看>>
思杰(Citrix)公司
查看>>
LTSP(linux Terminal server Poject)
查看>>
校友美女记者何小叶的blog
查看>>
CSS1规范
查看>>
Toms_zhang
查看>>
xzh2000
查看>>
3.配置PPP
查看>>
OSI参考模型的各层
查看>>
个人资讯
查看>>
chinaunix
查看>>
Apache Tomcat
查看>>
Unix 高级用户命令 lsof 和 fuser (zt)
查看>>
msn一直登陆不上,没有办法只好启用meebo!
查看>>
msn小工具适用!
查看>>
redhat ntsysv中一些服务的简单解释(zt)
查看>>
LSOF使用技巧 (zt)
查看>>
linux的日志文件
查看>>