Bug #65272 [Opn->Csd]: flock() documentation says LOCK_NB is not available on Windows, although it is

From: Date: Mon, 02 Feb 2015 16:31:02 +0000
Subject: Bug #65272 [Opn->Csd]: flock() documentation says LOCK_NB is not available on Windows, although it is
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-11910@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65272&edit=1 ID: 65272 Updated by: rdlowrey@php.net Reported by: benjamin dot morel at gmail dot com Summary: flock() documentation says LOCK_NB is not available on Windows, although it is -Status: Open +Status: Closed Type: Bug Package: Documentation problem Operating System: N/A PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Automatic comment on behalf of rdlowrey Revision: http://git.php.net/?p=php-src.git;a=commit;h=f2f467bd9609f5fad2491a4718380fadaa449470 Log: Fixed bug #65272: correctly set flock() out param in windows Previous Comments: ------------------------------------------------------------------------ [2013-07-16 15:09:10] benjamin dot morel at gmail dot com Description: ------------ The flock() documentation: http://php.net/manual/en/function.flock.php Says: 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) In my tests on Windows 7 x64, it does work. But what is true is that the failed flock() does not set &$wouldblock to 1. Please see the test script below. Both scripts must be run at the same time in PHP interactive mode or with a sleep() to avoid the lock being released automatically. It would be interesting to test this behaviour on other versions of Windows (this might not be applicable to all of them), and update the documentation accordingly. Non-blocking locks are a really useful feature, and it would be nice to document this properly for Windows users. Test script: --------------- Script 1 -------- $f = fopen('file.txt', 'w'); var_export(flock($f, LOCK_EX | LOCK_NB, $wouldblock)); // true var_export($wouldblock); // 0 Script 2 -------- $f = fopen('file.txt', 'w'); var_export(flock($f, LOCK_EX | LOCK_NB, $wouldblock)); // false var_export($wouldblock); // 0 (1 on Linux) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65272&edit=1

« previous php.doc.bugs (#11910) next »