|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-12-06 10:38 UTC] mike dot duncan at sonopress dot com
Here is my src:
--------------------
$files = array();
$dirs = array();
function getMD5OfFile($f) {
return md5_file($f);
//return exec("md5sum ".$f." | awk '{print $1}'");
}
function getFiles($d) {
global $files, $dirs;
clearstatcache();
if($dir = @opendir($d)) {
while(($file = @readdir($dir)) !== false) {
if(($file != ".") && ($file != "..")) {
if(is_dir($d."/".$file)) $dirs[] = $d."/".$file;
elseif(is_file($d."/".$file) && (substr($file,0,1) != ".")) $files[] = $d."/".$file;
}
}
}
}
/** Get files for directories **/
getFiles("/home/webdev");
while(($dir = array_shift($dirs)) !== null) {
getFiles($dir);
}
/** Ouptut findings **/
while(($file = array_shift($files)) !== null) {
echo $file.": ". getMD5FromFile($file) ."\n";
}
------------------
I first tried this with v4.2.1. What I am trying to do is get the MD5 for every file within the filesystem. Unfortunately this code freezes after about 20 or so files (md5_file() or exec() returns ok until then). If I uncomment the exec() return and comment the md5_file() return, the script hangs at exactly the same spot. If comment both out and run the script without md5'ing any files, I get a listing of all files (no problem).
I have also tried replacing the md5_file() code with one that was listed here http://www.php.net/manual/en/function.md5-file.php that will read the file into a variable and do a md5() on that var. Unfortunately I got a FATAL: emalloc() error using that method.
Finally, I tried getting the upgrading to v4.3.0-dev (latest snapshot from snaps) and got the same results.
I cannot figure out why this hangs and does not bomb out. I think it has something to do with maybe a cache of some sort or the memory buffers are filling up. Maybe even something to with how I am traversing the array of directories? But then, why would it work without the md5 cals? I do not know, but I thought I would post it here and see what you guys think. TIA.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 10:00:01 2025 UTC |
I also tried adding ini_set("max_execution_time", "180") to the script and it changed nothing. Just to make sure it was not hitting this limit too.