我有代码,假设将8GB文件上传到服务器。我遇到的问题似乎是内存问题,因为我的服务器只有4GB的内存。我上传的脚本是:
$s3 = S3Client::factory(array(
'credentials' => $credentials
));;
// 2. Create a new multipart upload and get the upload ID.
$response = $s3->createMultipartUpload(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,
'curl.options' => array(
CURLOPT_TIMEOUT => 12000,
)
));
$uploadId = $response['UploadId'];
// 3. Upload the file in parts.
$file = fopen($body, 'r');
$parts = array();
$partNumber = 1;
while (!feof($file)) {
$result = $s3->uploadPart(array(
'Bucket' => $bucket,
'Key' => $obect,
'UploadId' => $uploadId,
'PartNumber' => $partNumber,
'Body' => fread($file, 10 * 1024 * 1024),
));
$parts[] = array(
'PartNumber' => $partNumber++,
'ETag' => $result['ETag'],
);
}
$result = $s3->completeMultipartUpload(array(
'Bucket' => $bucket,
'Key' => $obect
,
'UploadId' => $uploadId,
'Parts' => $parts,
));
$url = $result['Location'];
return true;
} catch (Aws\Exception\S3Exception $e) {
error_log($e -> getMessage() . ' ' . $e -> getTraceAsString());
return false;
} catch (Exception $e) {
error_log($e -> getMessage() . ' ' . $e -> getTraceAsString());
return false;
}
以前有人遇到过这个问题吗?我该如何解决内存问题?