Chris@0: 0) { Chris@0: // This function should only be called by a request that failed to get a Chris@0: // lock, so we sleep first to give the parallel request a chance to finish Chris@0: // and release the lock. Chris@0: usleep($sleep); Chris@0: // After each sleep, increase the value of $sleep until it reaches Chris@0: // 500ms, to reduce the potential for a lock stampede. Chris@0: $delay = $delay - $sleep; Chris@0: $sleep = min(500000, $sleep + 25000, $delay); Chris@0: if ($this->lockMayBeAvailable($name)) { Chris@0: // No longer need to wait. Chris@0: return FALSE; Chris@0: } Chris@0: } Chris@0: // The caller must still wait longer to get the lock. Chris@0: return TRUE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getLockId() { Chris@0: if (!isset($this->lockId)) { Chris@0: $this->lockId = uniqid(mt_rand(), TRUE); Chris@0: } Chris@0: return $this->lockId; Chris@0: } Chris@0: Chris@0: }