Sunday, August 14, 2011

PHP Daemon runs out of file resources

http://gnuvince.wordpress.com/2008/10/28/php-wrong-for-long-running-processes-wrong-for-america/

<?php
$fd = fopen('/etc/passwd', 'r');
echo "$fdn";
fclose($fd);

$fd = fopen('/etc/fstab', 'r');
echo "$fdn";
fclose($fd);
?>


And this shows the usual:
$ php fds.php
Resource id #5
Resource id #6

Python doesn't have this problem though.

PHP is reusing the file descriptors but counting up its file resource. When it gets to 2^31-1 files and then goes into negative numbers and when it gets to 0 it crashes. How can the process use that many file handles in a few weeks time?

How do you reuse old file descriptors or resources after they are closed so you can run the php script forever?

No comments: