Web Development

(no) locking files with timeout

Hell, am I the only one using flock in PHP with LOCK_NB? According to PHP: flock – Manual there is a parameter value of 4 for LOCK_NB – that means “check for lock only, but do nothing else”... Initial problem was that there is not timeout-parameter (like “wait for 10 seconds until you catch the lock or return with error if not”). Now wanting to implement that by hand I got an “Illegal operation argument” passing 4 (LOCK_NB) to flock.

Thanks to open source we can check the source to see the problem:


if (act < 1 || act > 3) {
php_error(E_WARNING, “Illegal operation argument”);
RETURN_FALSE;
}

Now what’s wrong? the code (PHP 4.3.x) or the documentation ?

What’s the commonly used workaround for locking files with timeout if it’s not even possible to “check” for a lock nor pass any timeout parameters?

Average rating
(0 votes)

Similar entries