How to set http timeouts for Amazon AWS SDK for PHP
Asked Answered
F

2

5

I'm using the Amazon AWS SDK for PHP (namely, version 2.7.16) to upload files to an S3 bucket. How can I set a timeout for http/tcp operations (connection, upload, etc.)? Although I've googled a lot I wasn't able to find out how.

Sample code I'm using:

$awsS3Client = Aws\S3\S3Client::factory(array(
        'key' => '...',
        'secret' => '...'
    ));

$awsS3Client->putObject(array(
            'Bucket' => '...',
            'Key'    => 'destin/ation.file',
            'ACL'    => 'private',
            'Body'   => 'content'
        ));

so I'd like to set a timeout on the putObject() call.

Thanks!

Fibrous answered 14/7, 2016 at 12:48 Comment(0)
F
8

Eventually I helped myself:

$awsS3Client = Aws\S3\S3Client::factory(array(
        'key' => '...',
        'secret' => '...'
        'curl.options' => array(
            CURLOPT_CONNECTTIMEOUT => 5,
            CURLOPT_TIMEOUT => 10,
        )
    ));

Looks like AWS PHP uses curl internally, so network related options are set this way.

Fibrous answered 14/7, 2016 at 21:4 Comment(1)
Aws\AwsClient::factory is now deprecated : docs.aws.amazon.com/aws-sdk-php/v3/api/… Using the constructor directly seems to do the same job.Vera
V
5

With SDK version 3 this can be configured using the http configuration key.

$awsS3Client = Aws\S3\S3Client([
        'key' => '...',
        'secret' => '...',
        'http' => [
            'connect_timeout' => 5,
            'timeout' => 10,
        ]
    ]);
Vera answered 6/8, 2021 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.