首页 >后端开发 >PHP问题 > 正文

php高负载解决方案是什么

原创2019-08-28 16:51:2402699

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高负载解决方案是什么的详细内容,更多请关注php中文网其它相关文章!

php中文网最新课程二维码

声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理

  • 相关标签:php 高负载 解决方案
  • 相关文章

    相关视频


    网友评论

    文明上网理性发言,请遵守 新闻评论服务协议

    我要评论
  • 专题推荐

    推荐视频教程
  • PHP零基础视频教程PHP零基础视频教程
  • PHP每日小知识(第二季)PHP每日小知识(第二季)
  • PHP语法基础与数据库详解教程PHP语法基础与数据库详解教程
  • PHP数据库编程零基础入门到精通PHP数据库编程零基础入门到精通
  • 视频教程分类