|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80737 blocking flock() with timeout
Submitted: 2021-02-12 10:50 UTC Modified: 2021-02-12 15:54 UTC
From: maggus dot staab+php at googlemail dot com Assigned:
Status: Open Package: Filesystem function related
PHP Version: 7.4.15 OS: ubuntu16/18/20
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-02-12 10:50 UTC] maggus dot staab+php at googlemail dot com
I did a lot of research regarding flock() and timeouts.

I found workarounds using pcntl_signal/alarm which only work on the CLI:

our current workaround is to use LOCK_NB in a loop + usleep() until it succeeds, which feels rather hacky and wastes a lot of IO especially on NFS based volumes.
This was the only way I found to get it working in a web sapi.

wouldn't it be possible to e.g. take a stream_set_timeout() into account for the blocking flock() case?

Test script:
$fd = fopen("/path/to/my/file", 'c+');

stream_set_timeout($fd, 0, 1);
var_dump(flock($fd, LOCK_EX)); // should return false on timeout

$info = stream_get_meta_data($fd);
var_dump($info); // should report a timeout


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-12 15:54 UTC]
-Type: Bug +Type: Feature/Change Request -Package: Streams related +Package: Filesystem function related
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Apr 19 13:01:25 2021 UTC