X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FLock%2FSemaphoreLockDriver.php;h=781e110b1708a83633d1497296448ba639632595;hb=c713c2bf622257dbecf223b5f58bf8a98dde9d65;hp=b4439743c85fcee74b2a7c54a1cfac8ef7c3219c;hpb=19209f6826fc513b5e1bc3460c212a4b80c02049;p=friendica.git diff --git a/src/Core/Lock/SemaphoreLockDriver.php b/src/Core/Lock/SemaphoreLockDriver.php index b4439743c8..781e110b17 100644 --- a/src/Core/Lock/SemaphoreLockDriver.php +++ b/src/Core/Lock/SemaphoreLockDriver.php @@ -2,6 +2,8 @@ namespace Friendica\Core\Lock; +use Friendica\Core\Cache; + class SemaphoreLockDriver extends AbstractLockDriver { private static $semaphore = []; @@ -14,17 +16,13 @@ class SemaphoreLockDriver extends AbstractLockDriver } /** - * @brief Creates a semaphore key - * - * @param string $key Name of the lock - * - * @return integer the semaphore key + * (@inheritdoc) */ private static function semaphoreKey($key) { $temp = get_temppath(); - $file = $temp.'/'.$key.'.sem'; + $file = $temp . '/' . $key . '.sem'; if (!file_exists($file)) { file_put_contents($file, $key); @@ -34,15 +32,9 @@ class SemaphoreLockDriver extends AbstractLockDriver } /** - * - * @brief Sets a lock for a given name - * - * @param string $key The Name of the lock - * @param integer $timeout Seconds until we give up - * - * @return boolean Was the lock successful? + * (@inheritdoc) */ - public function acquireLock($key, $timeout = 120) + public function acquireLock($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES) { self::$semaphore[$key] = sem_get(self::semaphoreKey($key)); if (self::$semaphore[$key]) { @@ -56,13 +48,9 @@ class SemaphoreLockDriver extends AbstractLockDriver } /** - * @brief Removes a lock if it was set by us - * - * @param string $key Name of the lock - * - * @return mixed + * (@inheritdoc) */ - public function releaseLock($key) + public function releaseLock($key, $override = false) { if (empty(self::$semaphore[$key])) { return false; @@ -75,13 +63,10 @@ class SemaphoreLockDriver extends AbstractLockDriver } /** - * @brief Checks, if a key is currently locked to a process - * - * @param string $key The name of the lock - * @return bool + * (@inheritdoc) */ public function isLocked($key) { - return @sem_get(self::$semaphore[$key]) !== false; + return isset(self::$semaphore[$key]); } }