filename = $filename; register_shutdown_function([$this,"release"]); } public function lock() { if (file_exists($this->filename)) { if (time() - filemtime($this->filename) < $this->maxLock) { throw new \RuntimeException("Lockfile {$this->filename} already exists"); } } touch($this->filename); $this->locked = true; } public function release() { if ($this->locked && file_exists($this->filename)) { unlink($this->filename); } $this->locked = false; } }