note 12209 deleted from function.flock by jimw
| From: | jimw@php.net | Date: | Sat, 08 Dec 2001 19:08:58 +0000 |
| Subject: | note 12209 deleted from function.flock by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22080@lists.php.net to get a copy of this message | ||
As of PHP4.04pl1 I find that the method of protecting your flock() via opening the file once as
'a', flock()ing it and then opening it again does not work in the Win32 version of PHP.
Any executed fwrite()s will silently fail.
I expect this has more to do with file locking under NT/2000 than with PHP, since I don't think
the file-locking for PHP is implemented internally anyway, so this may not be a PHP bug at all.
Nevertheless, this works..
$fd = fopen($my_file, 'a');
if ( $fd != 0 && flock($fd, LOCK_EX) && ftruncate( $fd, 0) ){
fwrite( $fd, $to_write );
} else {
print 'failed..';
}
fclose($fd);
If anyone knows why this isn't as safe as the other method (which I know works under *NIX),
please drop me a note.