Skip to content

Commit

Permalink
Remove unneeded curl close commands
Browse files Browse the repository at this point in the history
  • Loading branch information
JSlush611 committed Nov 18, 2023
1 parent 32c2618 commit 51dcd37
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Client
protected $fingerprint;

/** @var mixed */
protected $curlHandle;
protected $curlHandle = null;

public function __construct(int $portNumber = 23517, string $host = 'localhost')
{
Expand All @@ -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
Expand Down Expand Up @@ -58,10 +66,6 @@ public function performAvailabilityCheck(): bool

static::$cache[$this->fingerprint] = [$success, $expiresAt];
} finally {
if (isset($curlHandle)) {
curl_close($curlHandle);
}

return $success ?? false;
}
}
Expand All @@ -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
}
}

Expand Down Expand Up @@ -134,8 +132,6 @@ public function lockExists(string $lockName): bool
if ($exception instanceof StopExecutionRequested) {
throw $exception;
}
} finally {
curl_close($curlHandle);
}

return false;
Expand Down

0 comments on commit 51dcd37

Please sign in to comment.