Bug #18218: fclose crashes PHP and Apache
| From: | ray at unreal64 dot net | Date: | Mon, 08 Jul 2002 07:59:24 +0000 |
| Subject: | Bug #18218: fclose crashes PHP and Apache | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-13490@lists.php.net to get a copy of this message | ||
From: ray@unreal64.net
Operating system: Windows NT4.0
PHP version: 4.2.1
PHP Bug Type: Output Control
Bug description: fclose crashes PHP and Apache
Hi !
We are using OpenBSD as server-side OS, and Windoze for testing. I found a
problem, which can be a bug. If not, or someone allready reported (I
didn't find), I am sorry. This bug accurs only at Windoze - all works
perfect under OpenBSD.
I have code (pseudo):
fopen(file1,"r")
if (fopen(file2,"r")) {
stat(file1);
stat(file2);
// check timestamp
if (stat1 VS stat2) {
read(file2) into array (restore cache);
close(file1);
close(file2);
return;
}
close(file2);
}
// rebuild cache
read(file1);
close(file1);
process file1 data
// store cache
if (fopen(file3,"w+b")) {
fwrite(file3,serialize(...));
fclose(file3); /****** HERE Apache/php CRASHES
}
File1 is 'source'. File2 is 'cache' - read only. I check last modify
time,
if valid, then I read cache. If not, I process source, re-open cache
for writing and store datas.
At fclose process die.
If I remove fclose, all works fine (other file operations, DB access,
etc.).
If I remove initiali fopen for cache and time checking (fstat), then
fclose3
also works perfect.
My own opinion: openning files/stating them/closing causes PHP die.
Have a nice day,
Don't kill me :o)
Bye
Ray
There is original code (class function):
// read strings file
function cmdLngFile($fname) {
$fnamec="../cache/".basename($fname);
if (!file_exists($fname))
stlc_exit("lng file $fname not found");
$fd=@fopen($fname,"r");
if (empty($fd))
stlc_exit("can't read or empty lng $fname");
$fdc=@fopen($fnamec,"rb");
if (!empty($fdc)) {
$statn=fstat($fd);
$statc=fstat($fdc);
// use cache
if ($statn[9]<=$statc[9]) {
$cache=fread($fdc,filesize($fnamec));
$this->lngs=array_merge($this->lngs,unserialize($cache));
fclose($fd);
fclose($fdc);
return;
}
// need rebuild cache...
fclose($fdc);
}
$lng=fread($fd,filesize($fname));
fclose($fd);
// process file contents
$lnglen=strlen($lng);
...
nothing interested here, jsut process language file and
setup array $this->lngs in form array["language_id"] => "text"
// store cache
$fdcw=@fopen($fnamec,"w+b");
if (!empty($fdcw)) {
$cache=serialize($this->lngs);
fwrite($fdcw,$cache);
fflush($fdcw);
//!!!! PHP bug (?) - this falldown apache on windoze, BSD works
// keep comment for windoze
//fclose($fdcw);
}
}
--
Edit bug report at http://bugs.php.net/?id=18218&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18218&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18218&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18218&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18218&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18218&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18218&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18218&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18218&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18218&r=globals