PHP failed to ptrace(PEEKDATA) pid 1918: Input/output error (5) 解决
admin
2023-06-23 08:02:08
0

今天网站后台出现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的最大执行时间。


解决:

禁止slowlog

vim 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

相关内容

热门资讯

美财长:特朗普不会接受“糟糕的... △美国财政部长贝森特(资料图)当地时间5月28日,美国财政部长贝森特在简报会上表示,美国与伊朗谈判团...
知情人士:伊朗方面尚未同意任何... 当地时间5月28日,伊朗谈判代表团媒体团队成员赛义德·阿加卢表示,截至目前,伊朗方面尚未同意任何谅解...
古巴外长:古美双边谈判没有取得... △古巴外交部长罗德里格斯(资料图)当地时间5月28日,古巴外交部长布鲁诺·罗德里格斯表示,古巴与美国...
伊朗最高领袖强调维护民族团结 伊朗最高领袖穆杰塔巴28日发表书面讲话,强调维护民族团结与社会凝聚力,并呼吁伊朗各界共同维护国家统一...
消息称字节跳动正开发自有CPU... IT之家 5 月 28 日消息,据路透社援引三名知情人士消息称,由于芯片价格持续上涨、供应短缺时间拉...
李咏瑾: “科技的省心”,会不... “科技的省心”会不会日益造就人们“判断的懒惰”? 近日,两条有关“AI成为投诉对象甚至被告”的新闻,...
一卷胶带如何“撕”出诺贝尔奖?... 一层原子厚的材料,能有多神奇?日前,“追星就追科学家”校园公益科普活动邀请上海交通大学物理与天文学院...
广发银行多项成果入选“十四五”... 近日,第八届金融科技创新大会暨CITE2026人工智能与金融数智化创新发展论坛正式发布了“十四五”金...
人工智能如何构建伦理治理体系?... 5月28日,“智能时代的自主知识体系构建暨人工智能伦理与社会实验室建设学术研讨会”在华南师范大学举行...
前5个月地方债发行约4.8万亿 作者 | 第一财经 陈益刊在地方财政收支矛盾较大背景下,为了稳投资、防风险,地方政府靠前发行政府债券...