Bug #51969 [Opn->Fbk]: fwrite returns 1 when trying to write to a locked file
| From: | fa@php.net | Date: | Thu, 10 Jun 2010 10:04:35 +0000 |
| Subject: | Bug #51969 [Opn->Fbk]: fwrite returns 1 when trying to write to a locked file | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-151282@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51969&edit=1
ID: 51969
Updated by: fa@php.net
Reported by: scarduzio at gmail dot com
Summary: fwrite returns 1 when trying to write to a locked file
-Status: Open
+Status: Feedback
Type: Bug
Package: Filesystem function related
Operating System: Windows 7 x86
PHP Version: 5.3.2
New Comment:
From the manual:
"It is also possible to add LOCK_NB as a bitmask to one of the above
operations if you don't want flock() to block while locking. (not
supported on Windows)"
Then again path "/cache/lockable.txt" doesn't look like windows - so
what OS are you using?
And while I know that's possibly not directly related to your problem -
please clarify.
Previous Comments:
------------------------------------------------------------------------
[2010-06-01 23:45:32] scarduzio at gmail dot com
Description:
------------
When I try to write any length string with fwrite using a file handle I
previously
locked with flock, fwrite is of course unable to write, but will return
unexplicable value 1 instead of false.
Test script:
---------------
/*
Run two instances of this script in a rapid sequence
*/
$fp1 = fopen("/cache/lockable.txt","w");
if(flock($fp1, LOCK_EX | LOCK_NB)){
echo "locked fp1\n";
sleep(20);
}else{
$res = fwrite($fp1, "ABCDE");
if(false === $res){
echo "failed the write\n";
}
echo "I managed! fwrite returned: "; print_r($res);
}
Expected result:
----------------
I expect to read "failed to write" when a second instance of the script
is run,
since fwrite should return false as documentation says when fwrite is
not able to
write.
Actual result:
--------------
fwrite returns integer 1.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51969&edit=1