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個是最好的,建議使用壓力測試獲取最佳值 php
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是內存文件系統,放在內存中確定會快了 java
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 linux