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

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.