What is php fastcgi? How to implement fastcgi_PHP tutorial
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:
PHP version: Officially download PHP 5.4.16 VC9 x86 Non Thread SafeZIP version.
PHP path: C:php-5.4.16
Configuration steps:
- Extract the PHP file, change the directory name and put it on the C drive. The directory address is C:php-5.4.16
- 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:
- 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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
