Home > Backend Development > PHP Tutorial > What is php fastcgi? How to implement fastcgi_PHP tutorial

What is php fastcgi? How to implement fastcgi_PHP tutorial

WBOY
Release: 2016-07-13 10:50:36
Original
1091 people have browsed it

FastCGI is a scalable, high-speed communication interface between HTTP servers and dynamic scripting languages. Most popular HTTP servers support FastCGI, including Apache, Nginx, lighttpd, etc. At the same time, FastCGI is also supported by many scripting languages, including PHP, which is run with mod_fastcgi in PHP instead of the PHP acceleration mode run with mod_phpsusexec.

Features:

1. Persistent connection. No need to start and initialize for every request, it's fast.
2. It is said that it can make PHP execution 3 to 30 times faster. The reason is: the PHP interpreter is loaded into memory instead of being read from memory every time it is needed, greatly improving the performance of sites that rely on scripts.
3. Because there is no need to start and initialize every request, the usage of system resources (CPU) is also greatly reduced.
4. There is no need to modify the original PHP program at all.
5. There is only one available php.ini file. When you want to configure multiple php.ini files to meet different script needs, you need to disable PHP's fast CGI in its subdirectories. This ensures that other directories continue to be effective for CGI.

php runs in fastcgi mode under linux

1. Linux system
[root@localhost /]# cat /etc/redhat-release
CentOS release 5.2 (Final)
2. Install apache
Download and unzip apache. The version used in this article’s demonstration 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 just to demonstrate PHP running in fastcgi mode. For convenience, only select the necessary parameters to compile
[root@localhost]# cd httpd-2.2.19
[root@localhost]#./configure --enable-so
[root@localhost]#make
[root@localhost]#make install

3. Install mod_fcgid (note that it is mod_fcgid, not mod_fastcgi)
Download and unzip mod_fcgid. The version used in the test of this article 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]cd mod_fcgid-2.3.6
[root@localhost]APXS=/usr/local/apache2/bin/apxs ./configure.apxs
[root@localhost]make
[root@localhost]make install

Note: Some documents on the Internet do not have APXS=/usr/local/apache2/bin/apxs. For details, please refer to the README-FCGID document in the mod_fcgid software

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] cd php-5.3.6
[root@localhost]./configure --prefix=/usr/local --with-configure-file-path=/etc
[root@localhost]make
[root@localhost]make install

Note: If there is an error reported by a library file, please install the relevant library file. The author's system once reported an error with libxml2. yum install libxml2-devel solved the problem. Many documents on the Internet say that the --enable-fastcgi parameter should be used. The author did not find this parameter in ./configure --help. Instead, I found a --disable-cgi parameter, so I decided not to add --enable-fastcgi. This parameter, later confirmed that this parameter can be omitted. The --with-apxs2 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 apache configuration file
[root@localhost]# vi /usr/local/apache/conf/httpd.conf
Add the following
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
ProcessLifeTime 1800
MaxProcessCount 100
DefaultMinClassProcessCount 3
DefaultMaxClassProcessCount 8
IPCConnectTimeout 15
IPCCommTimeout 300
MaxRequestsPerProcess 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 I tested is placed under the htdocs directory, so the permissions of the htdocs directory require ExecCGI. If the directories are different, please give the directory ExecCGI permissions. Another LoadModule fcgid_module modules/mod_fcgid.so is automatically added when mod_fcgid is installed.

6. Verification

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

Configure FastCGI to run PHP in IIS7

Environment description:

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

Configuration steps:

  1. Extract the PHP file, change the directory name and put it on the C drive. The directory address is C:php-5.4.16
  2. Copy php.ini-production and rename it to php.ini. First refer to the PHP.ini parameter description for modification.
    And modify PHP to support FastCGI:
  3. Open the winmail site and add relevant options as shown below:
    Select "Handler Mapping":



    Select "Add module mapping":



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



    Select "Yes":



    Set "FastCGI" related options as shown below:





    The "Maximum number of instances" and "Maximum number of instance requests" in the above figure can be modified according to your own circumstances.
    "Maximum number of instances": If it is a Windows Server 2008 R2 operating system, setting the property to 0 allows IIS to automatically select the optimal number of FastCGI processes in the current execution environment.
    "Maximum number of instance requests": You can modify it according to your own situation, or you can modify it to 10,000.
    Add a variable: PHP_FCGI_MAX_REQUESTS value is: 10000

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632622.htmlTechArticleFastCGI is a scalable, high-speed interface for communication between HTTP servers and dynamic scripting languages. Most popular HTTP servers support FastCGI, including Apache, Nginx, lighttpd, etc., and...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template