FastCGI not fully advanced Guide (PHP version, Windows platform) _php tutorial

Source: Internet
Author: User
Tags server memory
Problem
FastCGI not fully advanced Guide (PHP version, Windows platform)
Workaround
What is fastcgi?
FastCGI is a language-independent, extensible architecture for CGI open extensions whose main behavior is to keep the CGI interpreter process in memory and thus achieve high performance. As we all know, the repeated loading of CGI interpreter is the main reason of poor CGI performance, if the CGI interpreter remains in memory and accepts the FASTCGI process manager scheduling, it can provide good performance, scalability, fail-over characteristics and so on.
FastCGI's official site in [url=http://www.fastcgi.com/] link Mark Http://www.fastcgi.com[/url]

How the FastCGI works is:
1. Load the FASTCGI Process Manager (IIS ISAPI or Apache Module) at Web Server startup;
2. The FASTCGI process Manager itself initializes, initiates multiple CGI interpreter processes (multiple Php-cgi.exe visible in Task Manager) and waits for a connection from the Web server.
3. When a client request arrives at 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 child process Php-cgi.exe.
4. After the fastcgi process finishes processing, the standard output and error information are returned from the same connection to the Web Server. When the fastcgi child process closes the connection, the request is processed to completion. The fastcgi child process then waits and processes the next connection from the FASTCGI process Manager (running in webserver). In the normal CGI mode, php-cgi.exe exits here.

In the above scenario, you can imagine how slow CGI is usually. Every Web request PHP must re-parse php.ini, reload all DLL extensions, and initialize all data structures. With fastcgi, all of this occurs only once when the process is started. An additional benefit is that the persistent database connection (persistent connection) can work.

Second, why use fastcgi, rather than multithreaded CGI interpreter?
This may be due to a variety of considerations, such as:
1, you can no matter how stable on the Windows platform using multithreaded CGI interpreter, either IIS ISAPI mode or Apache module mode, they always run for a period of time crashed. Strange, huh? But there is such a situation!
Of course, there are a lot of times you can use the multi-threaded CGI interpreter, however, you may find that the Web page sometimes error, no matter how to find the reason, and in the fastcgi way when the probability of this error will be greatly reduced. I don't know why, I think the CGI interpreter for the standalone address space may eventually be a little bit more stable than the shared address space.
2, Performance! Performance? Is it possible that fastcgi is faster than a multithreaded CGI interpreter? But sometimes it is, only test your site, to conclude. Why, I find it difficult to say, but there is information in the Zend Winenabler era, Zend is also recommended to use the Windows platform under the fastcgi rather than the IIS ISAPI or Apache Module, but now Zend do not do this product.

Iii. reasons for not using fastcgi
1, multi-process consumes more server memory than multithreading, the Php-cgi.exe interpreter consumes 7 to 25 megabytes per process, and multiplies this number by 50 or 100 to try.
2, performance. It's true that sometimes multithreaded CGI interpreters are faster, hehe, and sometimes it's stable.
3, CGI? It sounds very earthy, hehe.

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 did not join FASTCGI support by default, and if you want to work in an earlier version, you need to recompile it. We assume that PHP is installed in c:php, and that the executable file name that supports fastfcgi is php-cgi.exe.
Note: It is recommended to turn off Cgi.force_redirect in php.ini, enable fastcgi.impersonate, enable Cgi.rfc2616_header

2. Download [url=http://www.caraveo.com/fastcgi/fastcgi-0.6.zip] Link tag http://www.caraveo.com/fastcgi/fastcgi-0.6.zip[/ URL] and extract the Isapi_fcgi.dll into the c:php directory (not required in this directory, here is just a narrative convenient).

3. Use Regedit.exe to establish the following registry key:
HKEY_LOCAL_MACHINE:SoftwareFASTCGI.php (required)

4. The following key values are established under this key:
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, number of interpreters started by default at startup, default value 5
DWORD type: Maxservers, maximum number of interpreters, default 25
DWORD type: Incrementservers, increment number when interpreter is not enough, default 2
DWORD Type: Timeout, increment interpreter (exceeds startservers number of) survival time, default 600 (seconds)
DWORD type: ThreadPoolSize, thread pool size, only valid under IIS, default 10
DWORD type: Impersonate, IIS is valid only, if 1, the IIS security flag is used, and 0 turns off this attribute. Do not close it unless you are not concerned about security issues. Default 1
DWORD Type: Maxpostdata,post data pre-read byte limit, default 0
DWORD Type: Bypassauth, IIS only valid if 1 and Isapi_fcgi.dll is configured for IIS Filter, and IIS is configured to use Basic authentication, which forces all authentication requests to use IIS anonymous users. The purpose of this option is to allow scripts to implement their own security mechanisms. Default 0
Binary type: customvars, additional environment variable value, new row delimited, null end

5, if it is IIS6, add a Web service extension to C:phpisapi_fcgi.dll, and allow. The maximum number of worker processes in the application pool remains at 1.

6. Add an application extension mapping relationship:
1). In Internet Information Services Manager, select the root directory for the Web site or application.
2). Open the Directory Properties page (right-click on "Properties") and select "Home Directory".
3). Click the "Configure" button and select "Map" tab.
4). Click "Add ...", in the "executable" set to: C:phpisapi_fcgi.dll, the extension is set to. php, be sure to select "Confirm file exists" and then "OK" to save the settings.
5). Again, add support for. php3 or. phtml extensions (optional).
6). Save the settings and restart IIS.

7, test, at the same time request multiple Web pages, and then view the task manager of the process, the page after the completion of the Php-cgi.exe process continues to run does not exit.

Five, Apache configuration method
1. First make sure that you have correctly installed PHP 4.3.x and the updated version. Earlier versions of PHP did not join FASTCGI support by default, and if you want to work in an earlier version, you need to recompile it. We assume that PHP is installed in c:php, and that the executable file name that supports fastfcgi is php-cgi.exe.
Note: It is recommended to open Cgi.force_redirect in php.ini, close fastcgi.impersonate, and close cgi.rfc2616_headers.

2. Download [Url=http://www.fastcgi.com/dist/mod_fastcgi-2.4.2-ap20.dll] Link tag http://www.fastcgi.com/dist/mod_ Fastcgi-2.4.2-ap20.dll[/url], placed in the Apache 2.x modules directory.

3. Make sure Apache 2.x can run PHP correctly in CGI mode. The following lines exist in the httpd.conf:
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 in httpd.conf:
LoadModule Fastcgi_module Modules/mod_fastcgi-2.4.2-ap20.dll
# Description:-processes 3 here means three php-cgi.exe processes are started,
# Please refer to the FastCGI documentation for detailed parameters of Fastcgiserver.
Fastcgiserver "C:/php/php-cgi.exe"-processes 3

5, restart Apache, test ibid.

Six, Advanced Configuration
Imagine a scenario in which your server runs both Apache 2 and IIS 6, and two Web servers are running PHP applications. So, there are three possibilities:
A, PHP is installed by using IIS ISAPI and Apache module, and is run in multi-threaded mode. This has nothing to do with fastcgi.
B, one of the servers uses fastcgi mode and the other uses multithreading. This will work properly.
C, two are used fastcgi way, this is often not normal. The general performance is:
Two servers each start some php-cgi.exe processes, and then one of the servers does not interpret the PHP page, or the new php-cgi.exe process is derived in a moment (scary).

Why is it? I think it's probably because the authors of the two things I used above (IIS ISAPI and Apache module) probably didn't want to use them at the same time, huh? Think about it, Apache 2 and IIS 6 if you can share a batch of Php-cgi.exe interpreter, do not waste memory, it is estimated that there will be no scheduling problem.
Research and testing have proved that this idea is feasible. However, since Shane Caraveo does not provide the ability to use an external fastcgi service in an ISAPI DLL, it is only the IIS responsible for starting and managing Php-cgi.exe in this scenario, and then configuring Apache to use these IIS manages the Php-cgi.exe process.

Configuration method:
1. Configure IIS FastCGI as described in the previous four methods.
2, basically according to the above V method configuration Apache FastCGI, five. 4 instead of adding in httpd.conf:
LoadModule Fastcgi_module Modules/mod_fastcgi-2.4.2-ap20.dll
# Use an external FastCGI server, please refer to the FastCGI documentation.
Fastcgiexternalserver "C:/php/php-cgi.exe"-socket "php-fcgi"
Note: The value after the-socket parameter must match the value Bindpath in HKEY_LOCAL_MACHINE:SoftwareFASTCGI.php so that two fastcgi process managers will use the same named pipe to connect Php-cgi.exe.

Note: The php-cgi.exe process in this configuration is only managed by the FASTCGI process Manager in IIS, and the busy request of Apache does not cause fastcgi in IIS to dispatch more Php-cgi.exe processes. Therefore, when configuring FastCGI in IIS, you should make the Startservers value large enough to avoid a shortage of PHP interpreters. The same problem is that if IIS shuts down, then Apache will not find the PHP interpreter, this should be careful.

This brings a problem is: at this time php.ini cgi.force_redirect, fastcgi.impersonate, cgi.rfc2616_headers should be how to set it? This leaves you to think about it ... Oh

Another problem that may be encountered is that IIS is very idle, and after a while the IIS-initiated Php-cgi.exe exits, then Apache cannot explain PHP. At this point you can access the IIS Web site, php-cgi.exe up again, dizzy Oh. One suggestion is to use the process pool management of IIS 6 to turn off the idle timeout in the application pool, and set the run account in the application pool identity to match the Apache service startup account.


The netizen constructs the meaning:
Collection......
The netizen constructs the meaning:
Collection of
But I often hang out with fastcgi, several machine tests are the same, I do not know why
The netizen constructs the meaning:
Official download Address: [url=http://www.fastcgi.com/dist/] link Mark Http://www.fastcgi.com/dist/[/url]
Version has been upgraded to 2.4.6, the landlord's download address is not, this article should be relatively old

[url=http://www.111cn.cn/html/30/n-34030.html] link Mark Http://www.111cn.cn/html/30/n-34030.html[/url] This article looks at
There are two ways to make PHP work in Apache 2.0.x under Windows. One is to use a CGI executable, and the other is a DLL for the Apache module.
So from a certain point of view, the PHP4 installed in Apache module has better security and better execution efficiency and speed than CGI mode.

Question: PHP installed in the Apache module can not use fastcgi, that is, two are loaded with the Apache module, the installation of normal operation, but do not know what the difference between the use of the two?

fastcgi Apache module has some problems, such as will rot open process, hang off after also kill, lead to very unstable, fortunately there is fcgid this solution, not let fcgi toward the end ^ ^

Http://fastcgi.coremail.cn/index.cn.htm

[ ]
The netizen constructs the meaning:
Wood has been useful
The netizen constructs the meaning:
Mark
The netizen constructs the meaning:
Take it, [img]http://www.111cn.cn/bbs/images/smilies/default/lol.gif[/img]
The netizen constructs the meaning:
good!
The netizen constructs the meaning:
Nice ...... That's Apache model better than fcgi ..... [Img]http://www.111cn.cn/bbs/images/smilies/default/33.gif[/img] [img]http://www.111cn.cn/bbs/images/smilies/ DEFAULT/33.GIF[/IMG][IMG]HTTP://WWW.111CN.CN/BBS/IMAGES/SMILIES/DEFAULT/33.GIF[/IMG]
The netizen constructs the meaning:
Occupy Building Study

http://www.bkjia.com/PHPjc/632516.html www.bkjia.com true http://www.bkjia.com/PHPjc/632516.html techarticle problem FastCGI not fully advanced Guide (PHP version, Windows platform) workaround one, what is FastCGI? FastCGI is a language-independent, extensible architecture of CGI open extension, its main behavior ...

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