Req #80737 [Opn->Nab]: blocking flock() with timeout
| From: | krakjoe@php.net | Date: | Wed, 12 May 2021 06:14:48 +0000 |
| Subject: | Req #80737 [Opn->Nab]: blocking flock() with timeout | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233794@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80737&edit=1
ID: 80737
Updated by: krakjoe@php.net
Reported by: maggus dot staab+php at googlemail dot com
Summary: blocking flock() with timeout
-Status: Open
+Status: Not a bug
Type: Feature/Change Request
Package: Filesystem function related
Operating System: ubuntu16/18/20
PHP Version: 7.4.15
Block user comment: N
Private report: N
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
I'm afraid there's no portable way to achieve this, and so nothing we can (or should try
to) do in php-src.
Previous Comments:
------------------------------------------------------------------------
[2021-02-12 10:50:49] maggus dot staab+php at googlemail dot com
Description:
------------
I did a lot of research regarding flock() and timeouts.
I found workarounds using pcntl_signal/alarm which only work on the CLI:
https://github.com/php-lock/lock/blob/8b254edfe1400a733e3cde571e981687e6f6d804/classes/util/PcntlTimeout.php#L68-L94
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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80737&edit=1