0

我正在尝试使用 aws php sdk 将 14MB 目录上传到 s3。这些是以下场景及其结果

  1. 从我的本地系统(印度)上传到 s3(us-east-1):成功
  2. 从 ec2(ap-southeast-1) 上传到 s3(ap-southeast-1):成功
  3. 从 ec2(ap-southeast-1) 上传到 s3(us-east-1):失败

我使用过的以下代码

require('application/classes/vendor/autoload.php');
use Aws\S3\S3Client;
use Aws\Common\Credentials\Credentials;
use Aws\S3\Sync\UploadSyncBuilder;
use Guzzle\Log\ClosureLogAdapter;
use Guzzle\Plugin\Log\LogPlugin;

$newCredentials = new Credentials("API_KEY", "SECRET_KEY");
$s3 = S3Client::factory();
//$logPlugin = Guzzle\Plugin\Log\LogPlugin::getDebugPlugin();
$stream = fopen('out.log', 'w');

$logPlugin = new LogPlugin(new ClosureLogAdapter(function ($m) use ($stream) {
    fwrite($stream, $m . PHP_EOL);
}), "# Request:\n{request}\n\n# Response:\n{response}\n\n# Errors: {curl_code} {curl_error}", true);

$s3->addSubscriber($logPlugin);

$s3->setCredentials($newCredentials);
$s3->setRegion("us-east-1");
UploadSyncBuilder::getInstance()
->setClient($s3)
->setBucket("BUCKET")
->setAcl("public-read")
->uploadFromDirectory("/mnt/1410503562Welcome to Leap!.zip_ext")
->setKeyPrefix("customs3/game10906/1410501964WelcometoLeap.zip_ext")
->setConcurrency(5)
->build()
->transfer();

例外

PHP Fatal error:  Uncaught exception 'Guzzle\Service\Exception\CommandTransferException' with message 'Errors during multi transfer (Guzzle\Http\Exception\RequestException) ./application/classes/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Request.php line 569

Error completing request

#0 ./application/classes/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Request.php(378): Guzzle\Http\Message\Request->processResponse(Array)
#1 ./application/classes/vendor/guzzle/guzzle/src/Guzzle/Http/Message/EntityEnclosingRequest.php(49): Guzzle\Http\Message\Request->setState('complete', Array)
#2 ./application/classes/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php(286): Guzzle\Http\Message\EntityEnclosingRequest->setState('complete', Array)
#3 ./application/classes/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php(244): Guzzle\Http\Curl\CurlMulti->processResponse(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Curl\CurlHandle), Array)
#4 ./application/classes/vendor/guzzle/guzzle in /vol/selfserve/application/classes/vendor/guzzle/guzzle/src/Guzzle/Service/Exception/CommandTransferException.php on line 25

我也有设置日志来调试和挖掘 Guzzle 库。我发现当它失败时,对于请求没有响应。当我将并发设置为 1 时,它会成功但需要很长时间。即使在 2 并发时它也会失败。

如果任何文件失败,则整个上传失败,使其处于部分上传状态。如果出现故障,我找不到任何方法来设置重试选项。

感谢帮助!

4

1 回答 1

0

After contacting with AWS support I was able to solve this with their help. Issue was in guzzle library. Following is the response from AWS support

This error occurs when cURL fails to rewind a stream and does not associate an error with a curl handle. We've added checks to account for this situation and automatically retry. Please ensure that they are using the latest version of the SDK and version 3.9.2+ of Guzzle.

于 2014-09-17T08:06:18.830 回答