[英]PHP web application throwing “Too many open files”
I have a web application which uses php's native functions to write to files eg fopen()
, fwrite()
after writing to files at the end of the process, I close the file handle by doing fclose()
. 我有一个Web应用程序,该程序使用php的本机函数在过程结束后写入文件后使用fopen()
, fwrite()
文件进行写入,我通过执行fclose()
关闭文件句柄。
The web application also uses exec()
and shell_exec()
at some places to execute external programs. 该Web应用程序还在某些地方使用exec()
和shell_exec()
来执行外部程序。
This web application is mostly deployed on Linux servers. 该Web应用程序主要部署在Linux服务器上。 Recently on a production server, we noted an issue where it was not able to write to a file and was throwing this error: 最近在生产服务器上,我们注意到了一个无法写入文件并引发此错误的问题:
"Too many open files" “打开的文件太多”
So my question is: Is it possible that doing the above operations (file writing and executing external commands via PHP) may have caused this and opened too many open files and I am getting this error now? 所以我的问题是:进行上述操作(通过PHP编写文件和执行外部命令)是否可能导致此问题并打开了太多打开的文件,而我现在收到此错误?
I have made sure that upon opening the file handles for writing / reading, I close them. 我确保打开用于写/读的文件句柄后,将它们关闭。
Is it possible? 可能吗? Sure. 当然。 It's even likely, since ulimit is a per-process limit. 甚至有可能,因为ulimit是每个进程的限制。
Maybe there's a flow issue that keeps your fclose
code from running (like an exception, or an else block?). 也许有,让您的流量问题fclose
代码运行(如异常,或者一个else块?)。
Do some debugging. 做一些调试。 Even something basic like incrementing a counter on fopen() and decrementing it on fclose() would be telling. 即使是一些基本的像递增)上的fopen计数器(和递减它FCLOSE()会告诉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.