[英]Intermittent “too many open files” when including/requiring PHP scripts
On my development box (thank goodness it's not happening in production—that I know of—yet), as I'm working on a PHP site, I get this occasional error: 在我的开发箱上(谢天谢地,它还没有在生产中发生(据我所知)),当我在一个PHP网站上工作时,偶尔会出现以下错误:
Warning: require_once( filename.php ): failed to open stream: Too many open files in path /functions.php on line 502
警告:require_once( filename.php ):无法打开流:在第502行的/functions.php 路径中打开文件过多
Fatal error: require_once(): Failed opening required ' filename.php ' (include_path='/my/include/path') in path /functions.php on line 502
致命错误:require_once():无法在第502行的路径 /functions.php中打开所需的' filename.php '(include_path ='/ my / include / path')
Line 502 of functions.php is my "autoload" function which automatically requires PHP files containing classes I use: functions.php的第502行是我的“自动加载”函数,该函数自动需要包含我使用的类的PHP文件:
function autoload($className)
{
require_once $className . ".php"; // <-- Line 502
}
By an "occasional" error, I mean that it'll work fine for about a day of development, then when I first see this, I can refresh the page and it'll be okay again, then refreshing gives me the same error. 出现“偶尔的”错误,是指它在大约一天的开发过程中都可以正常工作,然后,当我第一次看到此错误时,我可以刷新页面,并且一切都会好起来的,然后刷新也会给我同样的错误。 This happens just a few times before it starts to show it every time.
在每次开始显示之前,这种情况只发生了几次。 And sometimes the name of the file it's requiring (I have a script split out into several PHP files) is different... it's not always the first or last or middle files that it bombs on.
有时所需的文件名(我将一个脚本分成几个PHP文件)是不同的……它不一定总是轰炸的第一个,最后一个或中间文件。
Restarting php-fpm seems to solve the symptoms, but not the problem in the long run. 重新启动php-fpm似乎可以解决问题,但从长远来看并不能解决问题。
I'm running PHP 5.5.3 on my Mac (OS X 10.8) with nginx 1.4.2 via php-fpm. 我在Mac(OS X 10.8)和nginx 1.4.2上通过php-fpm运行PHP 5.5.3。
Running lsof | grep php-fpm | wc -l
运行
lsof | grep php-fpm | wc -l
lsof | grep php-fpm | wc -l
lsof | grep php-fpm | wc -l
tells me that php-fpm has 824 files open. lsof | grep php-fpm | wc -l
告诉我php-fpm已打开824个文件。 When I examined the actual output, I saw that, along with some .so
and .dylib
files, the vast majority of lines were like this: 当我检查实际输出时,我发现,连同一些
.so
和.dylib
文件,绝大多数行是这样的:
php-fpm 4093 myuser 69u unix 0x45bc1a64810eb32b 0t0 ->(none)
The segment "69u" and the 0x45bc1a6481... number are different on each row. 每行上的段“ 69u”和0x45bc1a6481 ...号不同。 What could this mean?
这意味着什么? Is this the problem?
这是问题吗? (
ulimit
is "unlimited") (
ulimit
为“无限”)
Incidentally (though perhaps un-related), there's also one or two of these: 顺便说一句(尽管可能不相关),其中也有一个或两个:
php-fpm 4093 myuser 8u IPv4 0x45bc1a646b0f97b3 0t0 TCP 192.168.1.2:59611->rest.nexmo.com:https (CLOSE_WAIT)
(I have some pages which use HttpRequest (PECL libraries) to call out to the Nexmo API. Are these not being closed properly or something? How can I crack down on those?) (我有一些页面使用HttpRequest(PECL库)来调出Nexmo API。这些页面没有正确关闭或关闭吗?我该如何对其进行打击?)
Try to set php-fpm (they're set to infinite by default) to more appropriate values on your needs. 尝试根据需要将php-fpm(默认情况下设置为无穷)设置为更合适的值。
For example: 例如:
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 10s
Maybe, set this too if your app works with lots of files: 也许,如果您的应用程序可以处理大量文件,也可以设置此设置:
rlimit_files = 1024
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.