S3桶亚马逊问题 [英] S3 Bucket Amazon issue

查看:155
本文介绍了S3桶亚马逊问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)我已经上传的形式

1) I have upload form

2)它上传文件到我的本地存储move_uploaded_file。

2) It uploads file to my local storage move_uploaded_file.

3)它使用Zend的putObject功能移动文件到S3的对象。

3) It uses zend putObject function to move file to s3 object.

一切工作正常,直到我有大约30MB的文件大小为40 MB。问题是,当我尝试上传大文件,如80 MB,100 MB左右,转移到S3文件需要年龄完成上传。我的code是这样的:

Everything works ok till I have file size of around 30Mb to 40 Mb. 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. 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));

你能帮如何处理大文件快速移动我试着用streamWrapper这样

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.

因此​​,是否有快速移动文件到S3存储的有效途径?

Hence, is there an efficient way to move file quickly to s3 bucket?

推荐答案

答案是一个工作进程。你可以在服务器启动通过PHP CLI启动一个PHP脚本的工人,或许还有一个GearmanClient PHP扩展和Gearman的服务器上运行框中。然后你排队一个后台作业,将文件上传到S3,而你的主站点的PHP code发出作业后返回成功,文件上传愉快地在后台,而你的网站的前景继续在这快乐的方式。这样做,正在另一台服务器的另一种方法做这一切的任务,而你的主站点仍然是利用免费的这个过程。现在我这样做。它运作良好。

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. 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. 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.

这篇关于S3桶亚马逊问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆