一、配置PHP-FastCGI
1、安装
wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
tar xzf mod_fastcgi-2.4.6.tar.gz
cd mod_fastcgi-2.4.6
cp Makefile.AP2 Makefile
make top_dir=/usr/local/apache
make top_dir=/usr/local/apache install
2、编辑httpd.conf配置文件,加入fastcgi模块装载代码:
LoadModule fastcgi_module modules/mod_fastcgi.so
3、配置apache支持php
编辑httpd.conf文件,加入如下代码:
### fastcgi ###
ScriptAlias /fcgi-bin/ "/usr/local/php/bin/"
AddHandler php-fastcgi .php
Action php-fastcgi /fcgi-bin/php-cgi
AddType application/x-httpd-php .php
<IfModule mod_fcgid.c>
AddHandler fcgid-script. .php .fcgi ### 暂时只配置支持.php
IdleTimeout 300
ProcessLifeTime 1800
MaxProcessCount 100
DefaultMinClassProcessCount 3
DefaultMaxClassProcessCount 8
IPCConnectTimeout 15
IPCCommTimeout 300
MaxRequestsPerProcess 100
</IfModule>
### fastcgi ###
4、编辑httpd.conf文件,建立虚拟主机可以这样配置:
<VirtualHost *:80>
DocumentRoot /usr/local/apache/htdocs
ServerName localhost
Options +ExecCGI
AddHandler fastcgi-script .fcgi
AddType application/x-httpd-php .php
Action application/x-httpd-php /fcgi-bin/php-cgi
<Directory /usr/local/apache/htdocs>
Options Indexes ExecCGI
Order allow,deny
allow from all
</Directory>
</VirtualHost>
二、压力测试
500人总共请求5000次,命令如下:
/usr/local/apache/bin/ab -c 500 -n 5000 http://localhost/index.php
以下为配置了PHP-FastCGI的测试结果:
以下为未配置PHP-FastCGI的测试结果:
三、总结
PHP-FastCGI的性能效果还是挺显著的。。
如想了解更多技术架构文章,扫码关注我的个人公众号以及转发分享哈~