如何为 PHP 的 Amazon AWS SDK 设置 http 超时

How to set http timeouts for Amazon AWS SDK for PHP

我正在使用 PHP 的 Amazon AWS SDK(即版本 2.7.16)将文件上传到 S3 存储桶。如何为 http/tcp 操作(连接、上传等)设置超时?虽然我在谷歌上搜索了很多,但我没能找到方法。

我正在使用的示例代码:

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

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

所以我想在 putObject() 调用上设置超时。

谢谢!

最终我帮助了自己:

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

看起来 AWS PHP 在内部使用 curl,所以网络相关的选项是这样设置的。

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

$awsS3Client = Aws\S3\S3Client([
        'key' => '...',
        'secret' => '...',
        'http' => [
            connect_timeout => 5,
            timeout => 10,
        ]
    ]);