如何使用 Guzzle 修改 curl 的超时时间?
How can I modify the timeout for curl with Guzzle?
我正在尝试使用 Guzzle 将 2GB 的文件上传到 Amazon S3。我正在流式传输内容,我的代码如下所示:
$credentials = new Credentials( 'access_id', 'access_key');
$s3 = S3Client::factory(array(
'credentials' => $credentials
));;
try {
$s3->putObject(array(
'Bucket' => $bucket,
'Key' => $obect,
'Body' => (strlen($body) < 1000 && file_exists($body)) ? Guzzle\Http\EntityBody::factory(fopen($body, 'r+')) : $body,
'ACL' => $acl,
'ContentType' => $content_type
));
return true;
} catch (Aws\Exception\S3Exception $e) {
error_log($e -> getMessage() . ' ' . $e -> getTraceAsString());
return false;
}
现在我得到的错误是:
Fatal error: Uncaught exception
'Guzzle\Http\Exception\CurlException' with message '[curl] 28:
Operation timed out after 30000 milliseconds with 0 out of -1 bytes
received [url]
https://xxxxx.s3.amazonaws.com/6e12e321-adac-42a0-a932-8f345f9dd9c6'
in
如何使用 Guzzle 修改 curl 的超时时间?
您可以通过这种方式设置 curl 选项:
$s3->putObject(array(
'Bucket' => '...',
'Key' => '...',
'Body' => '...',
'ACL' => '...',
'ContentType' => '...',
'curl.options' => array(
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 15
)
));
或者试试这个:
$s3->getConfig()->set('curl.options', array(
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 15
)
);
我正在尝试使用 Guzzle 将 2GB 的文件上传到 Amazon S3。我正在流式传输内容,我的代码如下所示:
$credentials = new Credentials( 'access_id', 'access_key');
$s3 = S3Client::factory(array(
'credentials' => $credentials
));;
try {
$s3->putObject(array(
'Bucket' => $bucket,
'Key' => $obect,
'Body' => (strlen($body) < 1000 && file_exists($body)) ? Guzzle\Http\EntityBody::factory(fopen($body, 'r+')) : $body,
'ACL' => $acl,
'ContentType' => $content_type
));
return true;
} catch (Aws\Exception\S3Exception $e) {
error_log($e -> getMessage() . ' ' . $e -> getTraceAsString());
return false;
}
现在我得到的错误是:
Fatal error: Uncaught exception 'Guzzle\Http\Exception\CurlException' with message '[curl] 28: Operation timed out after 30000 milliseconds with 0 out of -1 bytes received [url] https://xxxxx.s3.amazonaws.com/6e12e321-adac-42a0-a932-8f345f9dd9c6' in
如何使用 Guzzle 修改 curl 的超时时间?
您可以通过这种方式设置 curl 选项:
$s3->putObject(array(
'Bucket' => '...',
'Key' => '...',
'Body' => '...',
'ACL' => '...',
'ContentType' => '...',
'curl.options' => array(
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 15
)
));
或者试试这个:
$s3->getConfig()->set('curl.options', array(
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 15
)
);