Bug #67187 [Fbk->Csd]: Crash on interating file system when directory present
| From: | ignesia at gmail dot com | Date: | Thu, 08 May 2014 17:25:51 +0000 |
| Subject: | Bug #67187 [Fbk->Csd]: Crash on interating file system when directory present | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185724@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67187&edit=1
ID: 67187
User updated by: ignesia at gmail dot com
Reported by: ignesia at gmail dot com
Summary: Crash on interating file system when directory
present
-Status: Feedback
+Status: Closed
Type: Bug
Package: *Directory/Filesystem functions
Operating System: Ubuntu
PHP Version: 5.4.28
Block user comment: N
Private report: N
New Comment:
Thanks
Previous Comments:
------------------------------------------------------------------------
[2014-05-06 09:56:31] stasiu88 at gmail dot com
You're recursing infinitely over the same directory.
Try:
if($directory===null){
$directory = realpath('.') . DIRECTORY_SEPARATOR . 'content' .
DIRECTORY_SEPARATOR;
}
------------------------------------------------------------------------
[2014-05-03 10:31:22] ignesia at gmail dot com
Description:
------------
PHP crashes from "too many files open" when there is a minimum of 1 directory present.
ulimit -n = 1024
Test script:
---------------
function recursiveDirectoryIterator($directory = null, $files = array()) {
$directory = realpath('.') . DIRECTORY_SEPARATOR . 'content' .
DIRECTORY_SEPARATOR;
$iterator = new DirectoryIterator($directory);
foreach ($iterator as $info) {
if ($info->isFile ()) {
$files[$info->__toString ()] = $info;
} elseif (!$info->isDot ()) {
$list = array($info->__toString () => recursiveDirectoryIterator(
$directory.DIRECTORY_SEPARATOR.$info->__toString ()
));
if(!empty($files))
$files = array_merge_recursive($files, $filest);
else {
$files = $list;
}
}
}
return $files;
}
Expected result:
----------------
List all directories and files into an array recursively.
Actual result:
--------------
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message
'DirectoryIterator::__construct(/home/httpd/public_html/docs/content/): failed to open dir: Too
many open files' in /home/httpd/public_html/docs/index.php:65\nStack trace:\n#0
/home/httpd/public_html/docs/index.php(65):
DirectoryIterator->__construct('/home/httpd/pub...')\n#1
/home/httpd/public_html/docs/index.php(73):
recursiveDirectoryIterator('/home/httpd/pub...')\n#2
/home/httpd/public_html/docs/index.php(73):
recursiveDirectoryIterator('/home/httpd/pub...')\n#3
/home/httpd/public_html/docs/index.php(73):
recursiveDirectoryIterator('/home/httpd/pub...')\n#4
/home/httpd/public_html/docs/index.php(73):
recursiveDirectoryIterator('/home/httpd/pub...')\n#5
/home/httpd/public_html/docs/index.php(73):
recursiveDirectoryIterator('/home/httpd/pub...')\n#6
/home/httpd/public_html/docs/index.php(73):
recursiveDirectoryIterator('/home/httpd/pub...')\n#7
/home/httpd/public_html/docs/index.php(73): recursive!
DirectoryIterator('/home/httpd/p in /home/httpd/public_html/docs/index.php on line 65
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67187&edit=1