lock: flock with timeout support

I like FlockMutex because it work on kernel level and is reliable.

however there’s the problem that acquiring the lock makes program wait forever. I wish to get error “unable to obtain lock withing timeout”

for flock there’s LOCK_NB flag which can be used.

ps: SemaphoreMutex has similar issue

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Timeout support has been added to FlockMutex in the master branch.

It uses PCNTL if possible and busy waiting if not.

It’s not production ready! But is’t ready for some testing. Please report any issues here.

Having a timeout is actually a nice feature. LOCK_NB would turn the implementation into a busy waiting lock and suffer from being inacurate. I will consider this option as a last resort. But first I will see if pcntl_alarm might be a better option. However:

Process Control support in PHP is not enabled by default. […] Currently, this module will not function on non-Unix platforms (Windows).

This won’t be a low hanging fruit.