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:
Warning: require_once(filename.php): failed to open stream: Too many open
files in path/functions.php on line 502
Fatal error: require_once(): Failed opening required 'filename.php'
(include_path='my_include_path') in path/functions.php on line 502
Line 502 of functions.php is my "autoload" function, so I don't have to
manually "require_once" files of classes I'm using:
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.
Restarting php-fpm seems to solve the symptoms, but not the problem in the
long run.
I'm running PHP 5.5.3 on my Mac (OS X 10.8) with nginx 1.4.2 via php-fpm.
Running lsof | grep php-fpm | wc -l tells me that php-fpm has 824 files
open. When I examined the actual output, I saw that, along with some .so
and .dylib files, the vast majority of lines were like this:
php-fpm 4093 myuser 69u unix 0x45bc1a64810eb32b 0t0 ->(none)
The segment "69u" and the 0x45bc1a6481... number are different on each
row. What could this mean? Is this the problem? (ulimit is "unlimited")
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?)
No comments:
Post a Comment