Can I set timeout for Athena PHP (Laravel 8) SDK connection? [duplicate]

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 1:

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.

Solution 2:

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,
        ]
    ]);