下面4個參數的意思分別為:
pm.max_children:靜態方式下開啟的php-fpm進程數量。
pm.start_servers:動態方式下的起始php-fpm進程數量。
pm.min_spare_servers:動態方式下的最小php-fpm進程數量。
pm.max_spare_servers:動態方式下的最大php-fpm進程數量。
註:以記憶體512M的VPS來說,建議設定的參數如下,僅供參考:
pm=dynamic
pm.max_children=20
pm.start_servers=5
pm.min_spare_servers=5
pm.max_spare_servers=20
更詳細的最佳化設定
When you running a highload website with PHP-FPM via FastCGI, the following tips may be useful to you : )
如果您高負載網站使用PHP-FPM管理FastCGI,這些技巧也許對您有用:)
1. Compile PHP’s modules as less as possible, the simple the best (fast);
1.盡量少安裝PHP模組,最簡單是最好(快)的
2. Increas PHP FastCGI child number to 100 and even more. Sometime, 200 is OK! ( On 4GB memory server);
2.把您的PHP FastCGI子進程數調到100或以上,在4G記憶體的伺服器上200就可以
註:我的1g測試機,開64個是最好的,建議使用壓力測試擷取最佳值
3. Using SOCKET PHP FastCGI, and put into /dev/shm on Linux;
3.使用socket串連FastCGI,linux作業系統可以放在 /dev/shm中
註:在php-fpm.cnf裡設定<value name=”listen_address”>/tmp/nginx.socket</value>就可以通過socket串連FastCGI了,/dev/shm是記憶體檔案系統,放在記憶體中肯定會快了.記得這時也要在nginx裡的配置裡進行修改,保持一致.
代碼如下 |
複製代碼 |
location ~ .*.(php|php5)?$ { #將Nginx與FastCGI的通訊方式由TCP改為Unix Socket。TCP在高並發訪問下比Unix Socket穩定,但Unix Socket速度要比TCP快。www.111cn.nEt fastcgi_pass unix:/tmp/php-cgi.sock; #fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } |
4. Increase Linux “max open files”, using the following command (must be root):
代碼如下 |
複製代碼 |
# echo ‘ulimit -HSn 65536′ >> /etc/profile # echo ‘ulimit -HSn 65536 >> /etc/rc.local # source /etc/profile |
4.調高linux核心開啟檔案數量,可以使用這些命令(必須是root帳號)
代碼如下 |
複製代碼 |
echo ‘ulimit -HSn 65536′ >> /etc/profile echo ‘ulimit -HSn 65536′ >> /etc/rc.local source /etc/profile |
註:我是修改/etc/rc.local,加入ulimit -SHn 51200的
5. Increase PHP-FPM open file description rlimit:
代碼如下 |
複製代碼 |
# vi /path/to/php-fpm.conf Find “<value name=”rlimit_files”>1024</value>” Change 1024 to 4096 or higher number. Restart PHP-FPM. |
5. 增加 PHP-FPM 開啟檔案描述符的限制:
代碼如下 |
複製代碼 |
# vi /path/to/php-fpm.conf
|
找到“<value name=”rlimit_files”>1024</value>”
把1024 更改為 4096 或者更高.
重啟 PHP-FPM.
6. Using PHP code accelerator, e.g eAccelerator, XCache. And set “cache_dir” to /dev/shm on Linux.
6.使用php代碼加速器,例如 eAccelerator, XCache.在linux平台上可以把`cache_dir`指向 /dev/shm
一個外國網站建議的辦法
When you running a highload website with PHP-FPM via FastCGI, the following tips may be useful to you : )
如果您高負載網站使用PHP-FPM管 理FastCGI,這些技巧也許對您有用:)
1. Compile PHP’s modules as less as possible, the simple the best (fast);
1.盡量少安裝PHP模組,最簡單是最好(快)的 www.111cn.Net
2. Increas PHP FastCGI child number to 100 and even more. Sometime, 200 is OK! ( On 4GB memory server);
2.把您的PHP FastCGI子進程數調到100或以上,在4G記憶體的伺服器上200就可以
註:我的1g測試機,開64個是最好的,建議使用壓力測試擷取最佳值
3. Using SOCKET PHP FastCGI, and put into /dev/shm on Linux;
3.使用socket串連FastCGI,linux作業系統可以放在 /dev/shm中
註: 在php-fpm.cnf 裡設定/tmp/nginx.socket就可以通過socket串連 FastCGI了,/dev/shm是記憶體檔案系統,放在記憶體中肯定會快了
4. Increase Linux “max open files”, using the following command (must be root):
代碼如下 |
複製代碼 |
# echo ‘ulimit -HSn 65536′ >> /etc/profile # echo ‘ulimit -HSn 65536 >> /etc/rc.local # source /etc/profile
|
4.調高linux核心開啟檔案數量,可以使用這些命令(必須是root帳號)
代碼如下 |
複製代碼 |
echo ‘ulimit -HSn 65536′ >> /etc/profile echo ‘ulimit -HSn 65536′ >> /etc/rc.local source /etc/profile
|
註:我是修改/etc/rc.local,加入ulimit -SHn 51200的
5. Increase PHP-FPM open file description rlimit:
代碼如下 |
複製代碼 |
# vi /path/to/php-fpm.conf Find “1024” Change 1024 to 4096 or higher number. Restart PHP-FPM.
|
5. 增加 PHP-FPM 開啟檔案描述符的限制:
代碼如下 |
複製代碼 |
# vi /path/to/php-fpm.conf
|
找到“1024”
把1024 更改為 4096 或者更高.
重啟 PHP-FPM.
6. Using PHP code accelerator, e.g eAccelerator, XCache. And set “cache_dir” to /dev/shm on Linux.
6.使用php代碼加速器,例如 eAccelerator, XCache.在linux平台上可以把`cache_dir`指向 /dev/shm