我正在尝试使用AWS S3 API for PHP的
uploadDirectory功能将文件目录同步到我的S3存储桶。目录中有~4K个文件,总大小约为500GB。每个文件的大小在50到150 MB之间。但是,我随机且随意地看到以下错误
PHP Fatal error: Uncaught exception 'Aws\Exception\MultipartUploadException' with message 'An exception occurred while uploading parts to a multipart upload. The following parts had errors: - Part 5: Error executing "UploadPart" on "https://s3-us-west-2.amazonaws.com/my-bucket/raw/0234?partNumber=5&uploadId=uploadId"; AWS HTTP error: Error creating resource: [message] fopen(): SSL: An existing connection was forcibly closed by the remote host. [file] C:\php\aws\GuzzleHttp\Handler\StreamHandler.php [line] 312 [message] fopen(https://s3-us-west-2.amazonaws.com/my-bucket/raw/0234?partNumber=5&uploadId=uploadId): failed to open stream: HTTP request failed! [file] C:\php\aws\GuzzleHttp\Handler\StreamHandler.php [line] 312 ' in C:\php\aws\Aws\Multipart\AbstractUploadMana in C:\php\aws\Aws\Multipart\AbstractUploadManager.php on line 126 Fatal error: Uncaught exception 'Aws\Exception\MultipartUploadException' with message 'An exception occurred while uploading parts to a multipart upload. The following parts had errors:- Part 5: Error executing "UploadPart" on "https://s3-us-west-2.amazonaws.com/my-bucket/raw/0234?partNumber=5&uploadId=uploadId"; AWS HTTP error: Error creating resource: [message] fopen(): SSL: An existing connection was forcibly closed by the remote host. [file] C:\php\aws\GuzzleHttp\Handler\StreamHandler.php [line] 312 [message] fopen(https://s3-us-west-2.amazonaws.com/my-bucket/raw/0234?partNumber=5&uploadId=uploadId): failed to open stream: HTTP request failed! [file] C:\php\aws\GuzzleHttp\Handler\StreamHandler.php [line] 312 ' in C:\php\aws\Aws\Multipart\AbstractUploadMana in C:\php\aws\Aws\Multipart\AbstractUploadManager.php on line 126
从错误消息中看起来AWS出于某种原因正在放弃连接。这是我使用
的代码$s3Client = new Aws\S3\S3Client([ 'version' => 'latest', 'region' => 'us-west-2', 'http' => [ 'verify' => false ], 'credentials' => CredentialProvider::ini($user_name, $credentials_file_path) ]); $log_handler = fopen($path_to_log, 'a+'); $s3Client->uploadDirectory($path_to_dir, $bucket, null, array( 'debug' => $log_handler, 'concurrency' => 20 )); fclose($log_handler);
设置较低的并发性似乎允许进程在错误发生之前继续进行,但它似乎仍然是不可避免的。我还发现this article似乎表明可以从多部分上传错误中恢复,但我无法找到使其适用于此uploadDirectory函数的方法。
我使用的是最新版本的API,即2016年7月21日的3.18.32,不过在我使用该版本之前的一个月之前遇到了同样的问题。 PHP版本是5.6.22。