一、配置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的效能效果還是挺顯著的。。