PHP-FPM高負載荷技巧 (PHP-FPM on highload tips)

來源:互聯網
上載者:User
PHP-FPM高負載技巧 (PHP-FPM on highload tips)

原文地址:http://hi.baidu.com/pibuchou/blog/item/7cbccff0a3b77dc60b46e024.html

?

導致nginx 502 bad gateway的PHP-CGI(FASTCGI)

NGINX頻爆502 BAD GATEWAY的錯誤,看了網上的教程,仍沒有徹底解決。
目前我總結的解決502 BAD GATEWAY的方式有:
1.視伺服器的效能,在php-fmp.conf裡增加max_children的值,我目前用的15.
2.用reload參數定時重載php-fpm。這個主要原因是php指令碼執行時間過長造成的,重載php-fpm能杜絕這個問題。如何徹底解決php-cgi指令碼佔用大量記憶體從而導致502錯誤的產生還值得進一步探討,目前該做法不失為一種好辦法。
具體的做法是,用crontab讓php-fpm平滑重啟,從而不影響PHP指令碼的運行。
*/10 * * * * /usr/local/php/sbin/php-fpm reload

?

?

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裡設定/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

?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.