From 51dcd3731b20aa008e9e052b7edd624266f346a1 Mon Sep 17 00:00:00 2001 From: JSlush611 Date: Sat, 18 Nov 2023 09:39:33 -0600 Subject: [PATCH] Remove unneeded curl close commands --- src/Client.php | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/Client.php b/src/Client.php index 129bcbe..9d9e3f3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -20,7 +20,7 @@ class Client protected $fingerprint; /** @var mixed */ - protected $curlHandle; + protected $curlHandle = null; public function __construct(int $portNumber = 23517, string $host = 'localhost') { @@ -31,6 +31,14 @@ public function __construct(int $portNumber = 23517, string $host = 'localhost') $this->host = $host; } + public function __destruct() + { + if ($this->curlHandle) { + curl_close($this->curlHandle); + $this->curlHandle = null; + } + } + public function serverIsAvailable(): bool { // purge expired entries from the cache @@ -58,10 +66,6 @@ public function performAvailabilityCheck(): bool static::$cache[$this->fingerprint] = [$success, $expiresAt]; } finally { - if (isset($curlHandle)) { - curl_close($curlHandle); - } - return $success ?? false; } } @@ -72,25 +76,19 @@ public function send(Request $request): void return; } - try { - $curlHandle = $this->getCurlHandleForUrl('get', ''); + $curlHandle = $this->getCurlHandleForUrl('get', ''); - $curlError = null; + $curlError = null; - curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, $request->toJson()); - curl_exec($curlHandle); + curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, $request->toJson()); + curl_exec($curlHandle); - if (curl_errno($curlHandle)) { - $curlError = curl_error($curlHandle); - } + if (curl_errno($curlHandle)) { + $curlError = curl_error($curlHandle); + } - if ($curlError) { - // do nothing for now - } - } finally { - if (isset($curlHandle)) { - curl_close($curlHandle); - } + if ($curlError) { + // do nothing for now } } @@ -134,8 +132,6 @@ public function lockExists(string $lockName): bool if ($exception instanceof StopExecutionRequested) { throw $exception; } - } finally { - curl_close($curlHandle); } return false;