简体   繁体   English

S3 Bucket Amazon问题

[英]S3 Bucket Amazon issue

1) I have upload form 1)我有上传表格

2) It uploads file to my local storage move_uploaded_file. 2)它将文件上传到我的本地存储move_uploaded_file。

3) It uses zend putObject function to move file to s3 object. 3)它使用zend putObject函数将文件移动到s3对象。

Everything works ok till I have file size of around 30Mb to 40 Mb. 一切正常,直到我的文件大小在30Mb到40Mb之间。 The problem is when I try uploading larger files like 80 Mb, 100 Mb or so, the file moving to s3 takes ages to complete the upload. 问题是,当我尝试上传较大的文件(例如80 Mb,100 Mb左右)时,移至s3的文件要花一些时间才能完成上传。 My code is something like this: 我的代码是这样的:

$orginalPath = APPLICATION_PATH."/../storage/".$fileName;
move_uploaded_file($data['files']['tmp_name'], "$orginalPath");

$s3 = new Zend_Service_Amazon_S3($accessKey, $secretKey);

$s3->putObject($path, file_get_contents($orginalPath),
    array(Zend_Service_Amazon_S3::S3_ACL_HEADER =>Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ));

Can you help how to handle large files move quickly I tried using streamWrapper like this 您能帮我处理流大文件的问题吗?

$s3->registerStreamWrapper("s3");


file_put_contents("s3://my-bucket-name/orginal/$fileName", file_get_contents($orginalPath));

But no luck, it take same long time to move file. 但是没有运气,移动文件也需要很长时间。

Hence, is there an efficient way to move file quickly to s3 bucket? 因此,是否有一种有效的方法将文件快速移动到s3存储桶?

The answer is a worker process. 答案是一个工人过程。 You can start a PHP worker script via PHP CLI on server boot, perhaps with a GearmanClient php extension and gearman server running on your box. 您可以在服务器启动时通过PHP CLI启动PHP worker脚本,也许在您的机器上运行GearmanClient php扩展名和gearman服务器。 Then you queue a background job to upload the file to S3 while your main site PHP code returns success after issuing the job and the file happily uploads in the background while your foreground site continues on it's merry way. 然后,您将后台作业排队以将文件上传到S3,而主站点的PHP代码在发布该作业后返回成功,并且文件在后台愉快地上传,而前台站点则以快乐的方式继续上传。 Another way of doing this is making another server do all of this task while your main site remains utilization free of this process. 另一种执行此方法的方法是让另一台服务器执行所有此任务,而您的主站点仍保持利用率,而无需执行此过程。 I am doing this now. 我现在正在做。 It works well. 它运作良好。

You could consider using the more direct POST to S3 feature . 您可以考虑使用更直接的POST至S3功能 The AWS SDK for PHP has a class to help generate the data for the form . 适用于PHP的AWS开发工具包具有一个类,可帮助生成表单数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM