php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: maggus dot staab+php at googlemail dot com
New email:
PHP Version: OS:

 

 [2021-02-12 10:50 UTC] 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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-12 15:54 UTC] requinix@php.net
-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