public static function check_lock($lock, $limit = null, $timeout = null)
{
// Timeout, should a process die before its lock is freed
if (!is_numeric($timeout)) {
$timeout = LOCK_DEFULT_TIMEOUT_IN_MINUTES * \MINUTE_IN_SECONDS;
}
// Check for, and recover from, deadlock
if (self::get_lock_timestamp($lock) < time() - $timeout) {
self::reset_lock($lock);
return true;
}
// Default limit for concurrent events
if (!is_numeric($limit)) {
$limit = LOCK_DEFAULT_LIMIT;
}
// Check if process can run
if (self::get_lock_value($lock) >= $limit) {
return false;
} else {
wp_cache_incr(self::get_key($lock));
return true;
}
}