fileName = tempnam(sys_get_temp_dir(), 'mutex-') . '.lock'; } /** * {@inheritdoc} */ public function acquire() { // Try to create the lock file. If the file already exists, someone else // has the lock, so set an asynchronous timer and try again. while (($handle = @fopen($this->fileName, 'x')) === false) { yield Coroutine\sleep(self::LATENCY_TIMEOUT); } // Return a lock object that can be used to release the lock on the mutex. yield new Lock(function (Lock $lock) { $this->release(); }); fclose($handle); } /** * Releases the lock on the mutex. * * @throws MutexException If the unlock operation failed. */ protected function release() { $success = @unlink($this->fileName); if (!$success) { throw new MutexException('Failed to unlock the mutex file.'); } } }