解决NGINX+PHP-FPM failed to ptrace(PEEKDATA) Input/output error出错问题

网站总是出现bad gateway 提示,时有,时无,查看了一下日志,居然出现一堆错误,如下

[29-Mar-2014 22:40:10] ERROR: failed to ptrace(PEEKDATA) pid 4276: Input/output error (5)

[29-Mar-2014 22:53:54] ERROR: failed to ptrace(PEEKDATA) pid 4319: Input/output error (5)

[29-Mar-2014 22:56:30] ERROR: failed to ptrace(PEEKDATA) pid 4342: Input/output error (5)

[29-Mar-2014 22:56:34] ERROR: failed to ptrace(PEEKDATA) pid 4321: Input/output error (5)

[29-Mar-2014 22:56:40] ERROR: failed to ptrace(PEEKDATA) pid 4314: Input/output error (5)

网上也找了很多方法,很多人说是rlimit_files 打开文件数的问题,但是觉得不太靠谱,最后找到鬼佬的话,看上去还有几分道理。

http://serverfault.com/questions/406532/i-o-error-with-php5-fpm-ptracepeekdata-failed

It appears you have request_slowlog_timeoutenabled. 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:

  1. After php-fpm stops the process to trace it, the process fails to resume because of the error tracing it
  2. 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  然后,再设置 了 request_slowlog_timeout 这个参数,,所以后php 没有执行完就出错了。。

上面解决的办法是:

禁用 php-fpm.conf 里的  request_slowlog_timeout  和 slowlog  ,然后,修改 php.ini 里的 max_execution_time 参数


下面为英文版, 说的更详细,大家看看.

If you‘re running PHP-FPM you can see these kind of errors in your PHP-FPM logs.

$ tail -f php-fpm.log
[29-Dec-2015 23:03:10] NOTICE: child 11667 stopped for tracing
[29-Dec-2015 23:03:10] NOTICE: about to trace 11667[29-Dec-2015 23:03:10] ERROR: failed to ptrace(PEEKDATA) pid 11667: Input/output error (5)
[29-Dec-2015 23:03:10] NOTICE: finished trace of 11667

So, what do they mean?

They are the result of a configuration directive and a flaw in the way PHP-FPM handles requests.

Slowlog stacktraces

If your PHP-FPM configuration contains the request-slowlog-timeout parameter, the PHP-FPM master process will attempt to get a stacktrace of the running process when it exceeds that timeout.

It‘s a great way to identify ‘slow‘ processes and peek inside the request, to see what happened at that time. It mostly works, too.

On busy servers however, you can see the logs start to fill like this.

[29-Dec-2015 23:03:10] ERROR: failed to ptrace(PEEKDATA) pid 11667: Input/output error (5)
[29-Dec-2015 23:04:10] ERROR: failed to ptrace(PEEKDATA) pid 11668: Input/output error (5)
[29-Dec-2015 23:05:12] ERROR: failed to ptrace(PEEKDATA) pid 11668: Input/output error (5)
...

Avoiding these errors in the logs

First, let me start by saying it‘s a cosmetic issue: PHP itself isn‘t having problems. It‘s not even affected by this. But it can‘t log the stacktrace that was requested, so it reports this error.

If this bothers you, you can disable it by commenting the following 2 parameters in your PHP-FPM logs:

;slowlog = /var/log/php-fpm/slow.log
;request_slowlog_timeout = 5s

(you comment them by adding a semicolon in front of the line and restarting your PHP-FPM daemon)

That will make the errors disappear. It also stops any kind of slowlogging from ever happening.

What‘s causing the PEEKDATA error?

I already mentioned it‘s a result of a flaw in how PHP handles requests. This is explained in more detail here . The gist of it is:

... the worker is free to go when the master is determining slow execution. When stopping to be traced, it may have completed that execution and is in any stage serving another request, so the tracer gets the chance of failure or worse, dumping out the stack of an irrelevant execution.

FPM slow log sucks

In other words: when PHP‘s slowlog tries to get an actual stacktrace, it may send a signal to the master process which in turn finds the child process that is slow (which itfork() ‘d). However, by the time that happens, the child may have already finished its request and started serving another one.

Or it‘s not even handling a request at all, because it‘s finished and waiting for a new incoming request.

This leads to A) a stacktrace of the wrong process or B) the error you see above, a PEEKDATA error because there was no data to peek into.

So take that into account when reviewing PHP FPM slowlogs, too.


时间: 2024-10-13 06:31:44

解决NGINX+PHP-FPM failed to ptrace(PEEKDATA) Input/output error出错问题的相关文章

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

今天网站后台出现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] 

解决ubuntu挂载NTFS磁盘时出现input/output error

错误内容如下: Error mounting: mount exited with exit code 13: ntfs_attr_pread_i: ntfs_pread failed: Input/output error Failed to read NTFS $Bitmap: Input/output error NTFS is either inconsistent, or there is a hardware fault, or it's a SoftRAID/FakeRAID ha

Linux下“read failed after 0 of 4096 at 0: Input/output error”

1.故障描述( 在线移除一块被设置为pv格式的硬盘,提示unknown device报道):/dev/sdb1 /dev/sdc1 /dev/sdd1是组成/dev/vg_test/lvm_test的PV,这里我们模拟/dev/sdd1硬盘被直接断电了 [[email protected] mnt]# pvdisplay    /dev/sdd: read failed after 0 of 4096 at 0: Input/output error   /dev/sdd: read faile

svn Error: post-commit hook failed (exit code 127) with output

Command: Commit Modified: C:\Users\xsdff\Desktop\project\index.html Sending content: C:\Users\xsdff\Desktop\project\index.html Committing transaction...: Completed: At revision: 5 Error: post-commit hook failed (exit code 127) with output: Error: /sv

解决Nginx的connect() to 127.0.0.1:8080 failed (13: Permission denied) while connect

在进行Nginx+Tomcat 负载均衡的时候遇到了这个权限问题,在error.log日志中,我们可以看到如下: connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to upstream, 经过一番检查以及google,应该是SeLinux的导致的.可以选择一些两种方式进行: 1.关闭SeLinux,可以查看以下文章: CentOS下查看SeLinux状态及关闭SeLinux 2.执行下面的命令

解决Nginx的connect() to 127.0.0.1:8080,selinux

在进行Nginx+Tomcat 负载均衡的时候遇到了这个权限问题,在error.log日志中,我们可以看到如下: connect() to 127.0.0.1:8080 failed (13: Permission denied) while connecting to upstream, 经过一番检查以及google,应该是SeLinux的导致的.可以选择一些两种方式进行: getenforce    查看selinux状态 setenforce 0    (将selinux设置成Permis

linux操作系统重启后 解决nginx的pid消失问题

重启了linux服务器之后,进程性的 nginx -s stop后再次启动nginx -s reload ,总是会报错误nginx: [error] open() "/alidata/server/nginx/logs/nginx.pid" failed (2: No such file or directory),这应该是因为把nginx进程杀死后pid丢失了,下一次再开启nginx -s reload时无法启动,重装可以解决这个问题,但是太麻烦了. issued a nginx -

记录一次自己对nginx+fastcgi(fpm)+mysql压力测试结果

nginx + fastcgi(fpm) 压力测试: CentOS release 5.9 16核12G内存 静态页面: 并发1000,压测200秒,测试结果: 系统最大负载5.47 成功响应: 2563065, 502:0, 失败:0 PHP页面(对mysql进行一次带索引的查询,数据库记录500条): 并发1000,压测200秒,测试结果: 系统最大负载15.66 成功响应: 114368, 502:712, 失败:58715 并发200,压测200秒,测试结果: 系统最大负载25.81 成

解决nginx发布网站跨目录访问

解决nginx发布网站跨目录访问(thinkphp5+lnmp) 到:usr/local/nginx/conf/vim fastcgi.cof 把最后一行加上井号#注释掉保存重启 restart 参考:http://www.cnblogs.com/q1104460935/p/7028881.html