From: [EMAIL PROTECTED]
Operating system: SuSE 7.3 Pro
PHP version: 4CVS-2002-12-06 (stable)
PHP Bug Type: Filesystem function related
Bug description: md5_file() and exec() freeze
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.
--
Edit bug report at http://bugs.php.net/?id=20863&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=20863&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=20863&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=20863&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=20863&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=20863&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=20863&r=support
Expected behavior: http://bugs.php.net/fix.php?id=20863&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=20863&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=20863&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=20863&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20863&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=20863&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=20863&r=isapi