What is phpfastcgi? Fastcgi implementation _ PHP Tutorial

Source: Internet
Author: User
What is phpfastcgi? How to implement fastcgi. FastCGI is a scalable and fast interface for communication between HTTPserver and dynamic scripting languages. Most popular httpservers support FastCGI, including Apache, Nginx, and lighttpd. FastCGI is a scalable and fast interface for communication between HTTP server and dynamic scripting languages. Most popular HTTP servers support FastCGI, including Apache, Nginx, and lighttpd. at the same time, FastCGI is also supported by many script languages, including PHP, run mod_fastcgi in php instead of the php acceleration mode where mod_phpsusexec runs.

Features:

1. persistent connection. You do not have to start or initialize each request, but it is fast.
2. php execution speed is said to be 3 to 30 times faster. The reason is: the PHP interpreter program is loaded into the memory instead of reading from the memory every time it is needed, which greatly improves the performance of the site running by scripts.
3. because you do not have to start and initialize each request, it greatly reduces the usage of system resources (CPU.
4. there is no need to modify the original php program.
5. there is only one available php. ini file. When you need to configure multiple php. INI files to adapt to different script needs, you need to disable PHP's quick CGI in its subdirectory, so that other directories can continue to be effective for cgi.

Run php in fastcgi mode in linux

1. linux
[Root @ localhost/] # cat/etc/redhat-release
CentOS release 5.2 (Final)
2. install apache
Download and decompress apache. the version used in this article is 2.2.19.
[Root @ localhost] # wget http://labs.renren.com/apache-mirror//httpd/httpd-2.2.19.tar.gz
[Root @ localhost] # tar xvzf httpd-2.2.19.tar.gz

Compile and install apache. the purpose of this article is to demonstrate that php runs in fastcgi mode. for convenience, only the required parameter compilation is selected.
[Root @ localhost] # httpd-2.2.19 cd
[Root @ localhost] #./configure -- enable-so
[Root @ localhost] # make
[Root @ localhost] # make install

3. install mod_fcgid (Attention: mod_fcgid, not mod_fastcgi)
Download and decompress mod_fcgid. the version used in this test is 2.3.6.
[Root @ localhost] wget http://labs.renren.com/apache-mirror//httpd/mod_fcgid/mod_fcgid-2.3.6.tar.gz
[Root @ localhost] tar xvzf mod_fcgid-2.3.6.tar.gz

Compile and install mod_fcgid
[Root @ localhost] mod_fcgid-2.3.6 cd
[Root @ localhost] APXS =/usr/local/apache2/bin/apxs./configure. apxs
[Root @ localhost] make
[Root @ localhost] make install

Note: some documents on the network do not have APXS =/usr/local/apache2/bin/apxs. For more information, see the README-FCGID documentation in mod_fcgid.

4. install PHP
Download and compress PHP. The PHP version is 5.3.6.
[Root @ localhost] wget http://www.php.net/get/php-5.3.6.tar.bz2/from/cn.php.net/mirror
[Root @ localhost] tar xvjf php-5.3.6.tar.bz2

Compile and install PHP
[Root @ localhost] php-5.3.6 cd
[Root @ localhost]./configure -- prefix =/usr/local -- with-configure-file-path =/etc
[Root @ localhost] make
[Root @ localhost] make install

Note: If there is a library file error, please install the relevant library file, the author of the system has reported libxml2 error, yum install libxml2-devel, solve the problem. Many documents on the network say that the -- enable-fastcgi parameter should be used. /configure -- help does not find this parameter, but finds a -- disable-cgi parameter. Therefore, it is decided not to add the -- enable-fastcgi parameter. it is confirmed that this parameter can be left empty. -- With-apxs2 this parameter must not be added.

5. configuration

Create FastCGI script Directory
[Root @ localhost] # mkdir/usr/local/apache2/fcgi-bin
[Root @ localhost] # ln-s/usr/local/php/bin/php-cgi/usr/local/apache2/fcgi-bin/php-cgi

Edit the apache configuration file
[Root @ localhost] # vi/usr/local/apache/conf/httpd. conf
Add the following content
ScriptAlias/fcgi-bin/"/usr/local/php5/bin /"
AddHandler php-fastcgi. php
Action php-fastcgi/fcgi-bin/php-cgi
AddType application/x-httpd-php. php

IdleTimeout 300
Processlife 1800
MaxProcessCount 1, 100
DefaultMinClassProcessCount 3
DefaultMaxClassProcessCount 8
IPCConnectTimeout 15
IPCCommTimeout 300
Max requestsperprocess 100


AllowOverride None
Options FollowSymLinks + ExecCGI
Order allow, deny
Allow from all

Modify

Options Indexes FollowSymLinks + ExecCGI
AllowOverride None
Order allow, deny
Allow from all

Note: the test. php file tested by the author is placed under the htdocs Directory. Therefore, the permission for the htdocs directory must be ExecCGI. if the directory is different, grant the permission for the directory ExecCGI. In addition, when LoadModule fcgid_module modules/mod_fcgid.so is loaded with mod_fcgid, it is automatically added.

6. verification

Edit test page
[Root @ localhost] # vi/usr/local/apache2/htdocs/test. php
Echo phpinfo ();
?>

Configure FastCGI in IIS7 to run PHP

Environment description:

Operating system:Use windows 2008 server 64-bit system, IIS7.5
PHP version:Download PHP 5.4.16 VC9 x86 Non Thread SafeZIP officially.
PHP path:C: php-5.4.16

Configuration steps:

  1. Decompress the php file and change the directory name to drive C. Directory Address: C: php-5.4.16
  2. Copy php. ini-production and change it to php. ini. first, refer to the PHP. ini parameter description.
    Modify PHP support for FastCGI:
  3. To open the winmail site, click Add. related options are as follows:
    Select "handler ing ":



    Select "add module ing ":



    Select "module"-"FastCgiModule" and PHP path:



    Select "yes ":



    Set "FastCGI" related options as shown in the following figure:





    You can modify the "maximum number of instances" and "Maximum number of instance requests" based on your needs.
    "Maximum number of instances": if the Windows Server 2008 R2 operating system sets the attribute to 0, IIS can automatically select the optimal number of FastCGI processes in the current execution environment.
    "Maximum number of requests for an instance": you can modify the number of requests as per your needs or to 10000.
    Add a variable: PHP_FCGI_MAX_REQUESTS; value: 10000

Communication interface between the server and dynamic scripting language. Most popular HTTP servers support FastCGI, including Apache, Nginx, and lighttpd...

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.