您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php高负载解决方案是什么

2025/11/9 8:11:01发布16次查看
php高负载解决方案:
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);
尽量少安装php模块,最简单是最好(快)的。
2. increas php fastcgi child number to 100 and even more. sometime, 200 is ok! ( on 4gb memory server);
把您的php fastcgi子进程数调到100或以上,在4g内存的服务器上200就可以。
注:我的1g测试机,开64个是最好的,建议使用压力测试获取最佳值
3. using socket php fastcgi, and put into /dev/shm on linux;
使用socket连接fastcgi,linux操作系统可以放在 /dev/shm中。
相关推荐:《php入门教程》
注:在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快。
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
调高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.
增加 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.
使用php代码加速器,例如 eaccelerator, xcache.在linux平台上可以把`cache_dir`指向 /dev/shm
以上就是php高负载解决方案是什么的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product