Skip to content

Commit

Permalink
avoid executing curl_exec twice #527
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Nov 30, 2023
1 parent 8a5d7a1 commit 51b1aea
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Http/CurlDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public static function fetch(array $settings, ResponseFactoryInterface $response
{
if (count($requests) === 1) {
$connection = new static($settings, $requests[0]);
return [$connection->exec($responseFactory)];
curl_exec($connection->curl);
return [$connection->getResponse($responseFactory)];
}

//Init connections
Expand Down Expand Up @@ -77,7 +78,7 @@ public static function fetch(array $settings, ResponseFactoryInterface $response
curl_multi_close($multi);

return array_map(
fn ($connection) => $connection->exec($responseFactory),
fn ($connection) => $connection->getResponse($responseFactory),
$connections
);
}
Expand Down Expand Up @@ -113,10 +114,8 @@ private function __construct(array $settings, RequestInterface $request, StreamF
]);
}

private function exec(ResponseFactoryInterface $responseFactory): ResponseInterface
private function getResponse(ResponseFactoryInterface $responseFactory): ResponseInterface
{
curl_exec($this->curl);

$info = curl_getinfo($this->curl);

if ($this->error) {
Expand Down

0 comments on commit 51b1aea

Please sign in to comment.