diff --git a/src/Runner.php b/src/Runner.php index a31ebdc..8921e9c 100755 --- a/src/Runner.php +++ b/src/Runner.php @@ -5,9 +5,7 @@ class Runner { - /** - * @var string - */ + /** @var string */ private $lockPath; public function __construct(string $lockPath) @@ -21,7 +19,8 @@ public function runCallable(string $id, callable $callable) throw new \RuntimeException(sprintf('Directory `%s` was not created', $this->lockPath)); } - $resource = fopen($this->lockPath . '/' . $id . '.lock', 'w+'); + $lock = $this->lockPath . '/' . md5($id) . '.lock'; + $resource = fopen($lock, 'w+'); if (!flock($resource, LOCK_EX | LOCK_NB)) { // acquire an exclusive lock fclose($resource); return false; @@ -33,7 +32,7 @@ public function runCallable(string $id, callable $callable) throw $e; } finally { flock($resource, LOCK_UN); - unlink($this->lockPath . '/' . $id . '.lock'); + unlink($lock); fclose($resource); } @@ -46,4 +45,4 @@ public function run(string $id, IProcess $process) $process->run(); }); } -} \ No newline at end of file +}