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

Jul 13, 2016 am 10:50 AM
fastcgi http php server adjustable exist land accomplish how yes what is high speed

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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 Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

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.

See all articles