Reuse GuzzleClient with timeouts for presigned S3 requests

This commit is contained in:
Lance Pioch
2026-02-07 23:17:12 -05:00
parent c8dcff2ee9
commit ea978f3485

View File

@@ -12,6 +12,8 @@ use SimpleXMLElement;
class S3Filesystem extends AwsS3V3Adapter
{
private ?GuzzleClient $guzzle = null;
/**
* @param array<mixed> $options
*/
@@ -31,6 +33,18 @@ class S3Filesystem extends AwsS3V3Adapter
);
}
private function getGuzzleClient(): GuzzleClient
{
if ($this->guzzle === null) {
$this->guzzle = new GuzzleClient([
'timeout' => 30,
'connect_timeout' => 10,
]);
}
return $this->guzzle;
}
public function getClient(): S3ClientInterface
{
return $this->client;
@@ -51,8 +65,7 @@ class S3Filesystem extends AwsS3V3Adapter
{
$presignedRequest = $this->client->createPresignedRequest($command, '+60 minutes');
$guzzle = new GuzzleClient();
$response = $guzzle->send($presignedRequest);
$response = $this->getGuzzleClient()->send($presignedRequest);
$body = (string) $response->getBody();
$commandName = $command->getName();