note 75500 deleted from function.filesize by aidan

From: Date: Sat, 02 May 2009 11:17:54 +0000
Subject: note 75500 deleted from function.filesize by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154121@lists.php.net to get a copy of this message
Note Submitter: medhefgo at googlemail dot com ---- I created another dirsize() function which doesn't use recursion. I gained a ~2-3% performance boost while it uses ~50% lesser memory! <?php function dirsize($dirname) { if (!is_dir($dirname) || !is_readable($dirname)) { return false; } $dirname_stack[] = $dirname; $size = 0; do { $dirname = array_shift($dirname_stack); $handle = opendir($dirname); while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && is_readable($dirname . DIRECTORY_SEPARATOR . $file)) { if (is_dir($dirname . DIRECTORY_SEPARATOR . $file)) { $dirname_stack[] = $dirname . DIRECTORY_SEPARATOR . $file; } $size += filesize($dirname . DIRECTORY_SEPARATOR . $file); } } closedir($handle); } while (count($dirname_stack) > 0); return $size; } ?>

« previous php.notes (#154121) next »