Search code examples
amazon-s3aws-php-sdk

How to set http timeouts for Amazon AWS SDK for PHP


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!


Solution

  • 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.