|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67187 Crash on interating file system when directory present
Submitted: 2014-05-03 10:31 UTC Modified: 2014-05-08 23:34 UTC
From: ignesia at gmail dot com Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.4.28 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ignesia at gmail dot com
New email:
PHP Version: OS:


 [2014-05-03 10:31 UTC] ignesia at gmail dot com
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 ()
                $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): recursiveDirectoryIterator('/home/httpd/p in /home/httpd/public_html/docs/index.php on line 65


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-06 09:56 UTC] stasiu88 at gmail dot com
You're recursing infinitely over the same directory.


      $directory = realpath('.') . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR;
 [2014-05-06 17:15 UTC]
-Status: Open +Status: Feedback
 [2014-05-08 17:25 UTC] ignesia at gmail dot com
-Status: Feedback +Status: Closed
 [2014-05-08 17:25 UTC] ignesia at gmail dot com
 [2014-05-08 23:34 UTC]
-Status: Closed +Status: Not a bug
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Feb 23 08:01:29 2024 UTC