php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ignesia at gmail dot com
New email:
PHP Version: OS:

 

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

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-06 09:56 UTC] 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-06 17:15 UTC] requinix@php.net
-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
Thanks
 [2014-05-08 23:34 UTC] rasmus@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC