centos7 php性能调优

php-ini优化

vi /etc/php.ini

打开php的安全模式,控制php执行危险函数, 默认是Off,改为On

sql.safe_mode = Off

关闭php头部信息, 隐藏版本号, 默认是On,该为Off

expose_php = On

错误信息输出控制

display_error = Off

error_reporting = E_WARNING & E_ERROR

记录错误日志至后台, 方便追溯

log_errors = On

error_log = /var/log/php_error.log

每个脚本时间最大内存

memory_limit = 128M

上传文件最大许可,默认2M, 建议调整为16,32M

upload_max_filesize = 2M

禁止远程执行phpshell,默认On, 建议Off

allow_url_fopen = On

时区调整,默认PRC, 建议调整为Asia/Shanghai

date.timezone = PRC

整体优化后配置文件

sql.safe_mode = Off

expose_php = Off

display_error = Off

error_reporting = E_WARNING & E_ERROR

log_errors = On

error_log = /var/log/php_error.log

upload_max_filesize = 50M

allow_url_fopen = Off

date.timezone = Asia/Shanghai

php-fpm优化

PHP-FPM配置文件 4核16G、8核16G

[root@nginx ~]# cat /etc/php-fpm.d/www.conf

[global]

pid = /var/run/php-fpm.pid

#php-fpm程序错误日志

error_log = /var/log/php/php-fpm.log

log_level = warning

rlimit_files = 655350

events.mechanism = epoll

 

用户权限优化

[www]

user = nginx

group = nginx

listen = 127.0.0.1:9000

listen.owner = www

listen.group = www

listen.mode = 0660

 

listen.allowed_clients = 127.0.0.1

进程数优化

pm = dynamic

pm.max_children = 512   #一般来说一台服务器正常情况下每一个php-cgi所耗费的内存在20M左右,因此我的”max_children”我 设置成40个,20M*40=800M也就是说在峰值的时候所有PHP-CGI所耗内存在800M以内,低于我的有效内存1Gb。

pm.start_servers = 10

pm.min_spare_servers = 10

pm.max_spare_servers = 30

pm.process_idle_timeout = 15s;

最大请求数优化 

pm.max_requests = 2048

 

#php-www模块错误日志

php_flag[display_errors] = off

php_admin_value[error_log] = /var/log/php/php-www.log

php_admin_flag[log_errors] = on

 

#php慢查询日志

request_slowlog_timeout = 5s

slowlog = /var/log/php/php-slow.log

详细了解可以看看这个博客:https://www.cnblogs.com/kenshinobiy/p/7470635.html

posted @ 2018-06-19 14:43  Mr.zou  阅读(1001)  评论(0编辑  收藏  举报