Edit report at http://bugs.php.net/bug.php?id=51969&edit=1
ID: 51969 User updated by: scarduzio at gmail dot com Reported by: scarduzio at gmail dot com Summary: fwrite returns 1 when trying to write to a locked file -Status: Feedback +Status: Open Type: Bug Package: Filesystem function related Operating System: Windows 7 x86 PHP Version: 5.3.2 New Comment: Hi, thanks for replying. The OS in use is Windows 7 x86 genuine with all windows updates. The path with forward slash that I use in my code is unix style because I noticed PHP always translates it correctly into "C:\cache\lockable.txt", and it's always been fine. Also this time, the file is always found. About the manual line stating LOCK_NB bitmask is not supported: as evinced from my tests, including this one, the use of LOCK_NB is behaving perfectly since it detects file is locked, and executes my "else". I also do not think LOCK_NB is the core of this problem since I could split this script in two (one with the flock+sleep and the other with the "else" content) and reproduce the same bug. I later tested this in linux environment, fwrite will return 5 (not 1). Which is still funny, since writing in a locked file should in my opinion return false. I look forward for your further analysis. BR, Simone Previous Comments: ------------------------------------------------------------------------ [2010-06-10 12:04:33] f...@php.net >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. ------------------------------------------------------------------------ [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