php input/output error (5),PHP failed to ptrace(PEEKDATA) pid 1918: Input/output error (5) 解决

博客内容讲述了在遇到PHP-FPM中脚本执行缓慢及TIMEWAIT连接过多的问题时,如何进行排查和优化。通过调整PHP-FPM配置增加进程数,禁用请求慢日志,限制最大执行时间,以及优化系统内核参数如TCP_TIMEWAIT相关设置,最终解决了系统性能问题。
摘要由CSDN通过智能技术生成

今天网站后台出现504,前台出现此错误信息:[14-May-2016 12:03:44] WARNING: [pool www] child 25347, script '/usr/data/ckl-sapi/baiduNotify.php' (request: "POST /baiduNotify.php") executing too slow (10.818417 sec), logging

[14-May-2016 12:03:44] WARNING: [pool www] child 25269, script '/usr/data/ckl-sapi/baiduNotify.php' (request: "POST /baiduNotify.php") executing too slow (10.819982 sec), logging

[14-May-2016 12:03:44] WARNING: [pool www] child 25268, script '/usr/data/ckl-sapi/baiduNotify.php' (request: "POST /baiduNotify.php") executing too slow (12.392415 sec), logging

[14-May-2016 12:04:14] WARNING: [pool www] child 25369, script '/usr/data/ckl-sapi/baiduNotify.php' (request: "POST /baiduNotify.php") executing too slow (10.802581 sec), logging

[14-May-2016 12:17:33] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 12 total children

[14-May-2016 12:17:34] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 17 total children

[14-May-2016 12:17:35] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 4 idle, and 22 total children

从信息看,应该是php进程较少:

经过查看发现进程确实很少,解决如下:

修改配置文件增加进程vim /usr/local/php/etc/php-fpm.ini

pm = dynamic  #动态模式

pm.max_children = 512  #静态开启的进程数

pm.start_servers = 128 #动态模式的起始进程数

pm.min_spare_servers = 128 #动态模式最小进程数

pm.max_spare_servers = 512 #动态模式最大进程数

数值设置,参考自己的实际硬件配置,可以参考 内存/20M 来计算。

重新加载进程/etc/init.d/php-fpm reload

等待了一点时间发现又报错:[14-May-2016 12:21:29] ERROR: failed to ptrace(PEEKDATA) pid 27077: Input/output error (5)

[14-May-2016 12:22:13] WARNING: [pool www] child 27024, script '/usr/data/ckl-backend/index.php' (request: "GET /index.php") executing too slow (10.384578 sec), logging

[14-May-2016 12:22:13] ERROR: failed to ptrace(PEEKDATA) pid 27024: Input/output error (5)

[14-May-2016 12:23:33] WARNING: [pool www] child 26924, script '/usr/data/ckl-backend/index.php' (request: "GET /index.php") executing too slow (10.986032 sec), logging

[14-May-2016 12:23:33] ERROR: failed to ptrace(PEEKDATA) pid 26924: Input/output error (5)

[14-May-2016 12:26:29] WARNING: [pool www] child 1918, script '/usr/data/ckl-backend/index.php' (request: "GET /index.php") executing too slow (10.408103 sec), logging

[14-May-2016 12:26:29] ERROR: failed to ptrace(PEEKDATA) pid 1918: Input/output error (5)

查找资料如下:

It usrears you have request_slowlog_timeout enabled. This normally takes any request longer than N seconds, logs that it was taking a long time, then logs a stack trace of the script so you can see what it was doing that was taking so long.

In your case, the stack trace (to determine what the script is doing) is failing. If you're running out of processes, it is because either:

After php-fpm stops the process to trace it, the process fails to resume because of the error tracing it

The process is resuming but continues to run forever.

My first guess would be to disable request_slowlog_timeout. Since it's not working right, it may be doing more harm than good. If this doesn't fix the issue of running out of processes, then set the php.ini max_execution_time to something that will kill the script for sure.

大概说是设置了slowlog和php的最大执行时间。

解决:

禁止slowlogvim php-fpm.conf

;request_slowlog_timeout = 10s

;slowlog = /usr/local/log/php-fpm/ckl-slow.log

修改最大执行时间:vim php.ini

max_execution_time = 60

重启进程:/etc/init.d/php-fpm reload

等待一段时间,发现一切正常。

查看TCP连接相关:# ss -s

Total: 287 (kernel 380)

TCP:   597 (estab 122, closed 563, orphaned 0, synrecv 0, timewait 5630/0), ports 577

Transport Total     IP        IPv6

*         380       -         -

RAW       0         0         0

UDP       1         1         0

TCP       34        34        0

INET      35        35        0

FRAG      0         0         0

同时发现系统TIMEWAIT 较多,所以优化了一些内核相关参数# sysct -p

bash: sysct: command not found

[root@sapi etc]# sysctl -p

net.ipv4.ip_forward = 0

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.default.accept_source_route = 0

net.ipv4.tcp_max_tw_buckets = 6000

net.ipv4.ip_local_port_range = 1024 65000

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_max_orphans = 262144

net.ipv4.tcp_keepalive_time = 1200

net.ipv4.tcp_keepalive_intvl = 30

net.ipv4.tcp_keepalive_probes = 3

net.ipv4.tcp_synack_retries = 1

net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_max_orphans = 262144

net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_timestamps = 0

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.tcp_rmem = 4096 87380 4194304

net.ipv4.tcp_wmem = 4096 16384 4194304

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.core.somaxconn = 262144

kernel.sysrq = 0

kernel.core_uses_pid = 1

kernel.msgmnb = 65536

kernel.msgmax = 65536

kernel.shmmax = 68719476736

kernel.shmall = 4294967296

vm.swappiness = 0

fs.file-max = 409600

过一阵再查看:# ss -s

Total: 281 (kernel 362)

TCP:   520 (estab 22, closed 493, orphaned 0, synrecv 0, timewait 493/0), ports 475

Transport Total     IP        IPv6

*         362       -         -

RAW       0         0         0

UDP       1         1         0

TCP       27        27        0

INET      28        28        0

FRAG      0         0         0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值