php fastcgi是什么?fastcgi怎么实现
FastCGI是一个可伸缩地、高速地在HTTP server和动态脚本语言间通信的接口。多数流行的HTTP server都支持FastCGI,包括Apache、Nginx和lighttpd等,同时,FastCGI也被许多脚本语言所支持,其中就有PHP,在php里用mod_fastcgi 运行 而不是用 mod_phpsusexec 运行的php加速模式。
特点:
1、持久连接。不必对每一个请求都启动和初始化,速度很快。
2、据说可让php的执行速度快3到30倍。原因是:PHP解释程序被载入内存而不用每次需要时从存储器读取,极大的提升了依靠脚本运行的站点的性能。
3、因为不必对每一个请求都启动和初始化,所以也大大减少了系统资源(CPU)的占用。
4、对原来的php程序来说完全不用修改。
5、只有一个可用的php.ini文件。当要配置多个php.ini文件以适应不同的脚本需要时,你要在其子目录禁用PHP的快速CGI,如此则可保证其它目录继续对cgi有效。
linux下php以fastcgi模式运行
1、linux系统
[root@localhost /]# cat /etc/redhat-release
CentOS release 5.2 (Final)
2、安装apache
下载并解压缩apache,本文演示用的版本是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
编译和安装apache,本文的目的只是演示php以fastcgi方式运行,为了方便,只选必须的参数编译
[root@localhost]# cd httpd-2.2.19
[root@localhost]#./configure --enable-so
[root@localhost]#make
[root@localhost]#make install
3、安装mod_fcgid(注意是mod_fcgid,不是mod_fastcgi)
下载并解压缩mod_fcgid,本文测试时用的版本是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
编译并安装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
注释:网络上部分文档没有APXS=/usr/local/apache2/bin/apxs,详情参考mod_fcgid软件中的README-FCGID文档
4、安装PHP
下载并加压缩PHP,PHP版本是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
编译并安装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
注释:要是有库文件报错,请安装相关库文件,笔者的系统上曾报libxml2的错,yum install libxml2-devel,解决问题。网络上很多文档,说要使用--enable-fastcgi这个参数,笔者在./configure --help中没有找到这个参数,倒是找到一个--disable-cgi的参数,因而决定不加--enable-fastcgi这个参数,此后证实这个参数可以不加。--with-apxs2这个参数一定不能加。
5.配置
创建FastCGI脚本目录
[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
编辑apache配置文件
[root@localhost]# vi /usr/local/apache/conf/httpd.conf
加入以下内容
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
修改
Options Indexes FollowSymLinks +ExecCGI
AllowOverride None
Order allow,deny
Allow from all
注释:笔者测试的test.php文件放在htdocs目录下面,因此htdocs目录的权限需要ExecCGI,若目录不同,请赋予目录ExecCGI的权限。另LoadModule fcgid_module modules/mod_fcgid.so 这个再装mod_fcgid的时候,自动添加了。
6、验证
编辑测试页面
[root@localhost]# vi /usr/local/apache2/htdocs/test.php
echo phpinfo();
?>
IIS7中配置FastCGI运行PHP
环境说明:
PHP版本:官方下载PHP 5.4.16 VC9 x86 Non Thread SafeZIP版本。
PHP路径:C:php-5.4.16
配置步骤:
- 解压PHP文件,修改目录名放到C盘。目录地址为C:php-5.4.16
- 复制php.ini-production改名为php.ini,先参考PHP.ini参数说明修改。
并修改PHP对FastCGI支持:
- winmail站点打开按下图添加相关的选项:
选择“处理程序映射”:
选择“添加模块映射”:
选择“模块”-“FastCgiModule”和PHP路径 :
选择“是”:
按下图所示设置“FastCGI”相关选项:
上图中“最大实例数”和“实例最大请求数”可以根据自己情况修改。
“最大实例数”:如果是 Windows Server 2008 R2 操作系统将属性设置为 0,则可以使 IIS 自动选择当前执行环境下 FastCGI 进程的最佳数量。
“实例最大请求数”:可以根据自己情况修改,也可以修改到10000。
添加一条变量:PHP_FCGI_MAX_REQUESTS 值是: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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

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

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
