nginx php-fpm调优
問題:
發(fā)現(xiàn)/usr/local/webserver/php/etc/php-fpm.conf文件里定義的打開文件描述符的限制數(shù)量是
<value name="rlimit_files">51200</value>
但用 命令ulimit -n查看,發(fā)現(xiàn)只有1024
我已在/etc/rc.local里添加了
ulimit -SHn 51200
竟然沒生效
解決:
vi? /etc/security/limits.conf
文件最后加上
*??????? soft??? nofile? 51200
*??????? hard??? nofile? 51200
2、
問題:
用命令
netstat -np | grep 127.0.0.1:9000 |wc -l
發(fā)現(xiàn)只有100多
解決:
根據(jù)服務(wù)器內(nèi)存情況,可以把PHP FastCGI子進(jìn)程數(shù)調(diào)到100或以上,在4G內(nèi)存的服務(wù)器上200就可以
服務(wù)器上內(nèi)存為8G,我把PHP FastCGI子進(jìn)程數(shù)調(diào)整到300
vi /usr/local/webserver/php/etc/php-fpm.conf
將max_children修改為300
<value name="max_children">300</value>
重啟服務(wù)器,這樣,網(wǎng)站打開速度快,而且穩(wěn)定了。
?
When you running a highload website with PHP-FPM via FastCGI, the following tips may be useful to you : )
如果您高負(fù)載網(wǎng)站使用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子進(jìn)程數(shù)調(diào)到100或以上,在4G內(nèi)存的服務(wù)器上200就可以
注:我的1g測試機(jī),開64個是最好的,建議使用壓力測試獲取最佳值
3. Using SOCKET PHP FastCGI, and put into /dev/shm on Linux;
3.使用socket連接FastCGI,linux操作系統(tǒng)可以放在 /dev/shm中
注:在php-fpm.cnf 里設(shè)置<value name="listen_address">/tmp/nginx.socket</value>就可以通過socket連接 FastCGI了,/dev/shm是內(nèi)存文件系統(tǒng),放在內(nèi)存中肯定會快了? (這一步待確 認(rèn))
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.調(diào)高linux內(nèi)核打開文件數(shù)量,可以使用這些命令(必須是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
總結(jié)
以上是生活随笔為你收集整理的nginx php-fpm调优的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Javascript小括号“()”的多义
- 下一篇: 在IIS中删除ETag的方法