PHP之优化PHP-FPM

在上一篇,我们说到了安装opcahe来加速php
,那么还有其他方法可以优化吗?有的,本文我们来优化PHP-FPM

执行命令

vim /usr/local/php/etc/php-fpm
[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 20
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 20
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log

我们将其修改为

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static  #表示使用哪种进程数量管理方式,高并发下一般都是静态管理,初始就固定进程数
pm.max_children = 200   #子进程最大数,如果设置静态以下三个参数失效 4G内存以上设置200就可以
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 20
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log

重启php-fpm

you_server restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

现在再来测试

ab -c 150 -n 2000 http://192.168.2.101/log
Concurrency Level:      150
Time taken for tests:   12.869 seconds
Complete requests:      2000
Failed requests:        0
Write errors:           0
Total transferred:      546000 bytes
HTML transferred:       0 bytes
Requests per second:    154.21 [#/sec] (mean)
Time per request:       840.167 [ms] (mean)
Time per request:       6.434 [ms] (mean, across all concurrent requests)
Transfer rate:          38.45 [Kbytes/sec] received

相比之前文章的Requests per second: 120.74 [#/sec] (mean)现在又提高了到154,是不是很简单,当然如果这不是一台Mac创建的四台虚拟机的话,这个数值还会更高

你可能感兴趣的:(PHP之优化PHP-FPM)