flock() documentation says LOCK_NB is not available on Windows, although it is
| Bug #65272 | flock() documentation says LOCK_NB is not available on Windows, although it is | ||||
|---|---|---|---|---|---|
| Submitted: | 2013-07-16 15:09 UTC | Modified: | 2015-02-21 13:20 UTC | ||
| From: | benjamin dot morel at gmail dot com | Assigned: | ab (profile) | ||
| Status: | Closed | Package: | Documentation problem | ||
| PHP Version: | Irrelevant | OS: | N/A | ||
| Private report: | No | CVE-ID: | None | ||
[2013-07-16 15:09 UTC] 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)
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2015-02-02 16:38 UTC] rdlowrey@php.net
[2015-02-02 16:43 UTC] benjamin dot morel at gmail dot com
[2015-02-02 18:46 UTC] peehaa@php.net
[2015-02-21 12:34 UTC] ab@php.net
-Assigned To: +Assigned To: ab
[2015-02-21 12:34 UTC] ab@php.net
[2015-02-21 13:20 UTC] ab@php.net