handle !== null) { throw new RuntimeException('Verificação periódica já adquirida nesta instância.'); } $handle = fopen(storage_path('framework/replenishment-command.lock'), 'c'); if ($handle === false) { throw new RuntimeException('Não foi possível abrir o controlo da verificação periódica.'); } if (! flock($handle, LOCK_EX | LOCK_NB)) { fclose($handle); return false; } $this->handle = $handle; return true; } public function release(): void { if ($this->handle !== null) { flock($this->handle, LOCK_UN); fclose($this->handle); $this->handle = null; } } public function __destruct() { $this->release(); } }