在Laravel中实现图像处理的队列-要排队什么而不要排队什么? [英] Implementing queue for image processing in Laravel - what to queue and what not to?

查看:105
本文介绍了在Laravel中实现图像处理的队列-要排队什么而不要排队什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于Laravel的图像密集型应用程序.调整大小后,用户可以将图像上传到服务器,并且图像会存储在Amazon s3存储桶中.这里的过程非常缓慢,我一直在阅读队列,认为它们可能正是我需要将存储在亚马逊上的部分委派给我的东西.唯一的事情是这是我的postAction,可以处理上传:

I have a Laravel based application which is image intensive. Users can upload images to the server and the images are stored on Amazon s3 bucket after being resized. The process is pretty slow here and I've been reading up on queues and think they may be exactly what i need to kind of delegate the part of storing on amazon to. The only thing is that this is my postAction which handles the uploading:

public function postImage(){
        $images = Input::only('images');
        $model->saveImages($images['images']);
}

每个模型都有多个照片对象-照片是对数据库中图像的引用.因此,该模型的保存图像功能是:

Every model has multiple photo objects - a photo is a reference to an image in the db. So the save images function of the model is:

function saveImages($images){
    foreach($images as $image)
    {
      if(is_null($image)){
        continue;
      }
      $photo = new Photo();
      $photo->image = $image;
      $photo->save();
      $this->photos()->save($photo);
    }   

}

Photo类实现了 laravel订书机界面-因此它会自动处理上传到亚马逊s3.

The Photo class implements the laravel stapler interface - so it automatically handles the part of uploading to amazon s3.

如果我要设置队列-我不知道该将什么推送到队列以及如何实现?

If I were to set up a queue - I'm puzzled on what would I push to a queue and how would I implement it?

推荐答案

您不能将上传"过程排队.

You cant queue the 'upload' process.

您可能想做的是使用前端上的 DropzoneJS 之类的文件来进行AJAX上传(以及仍然在后端使用装订器).这样,用户可以上传1->许多文件,并查看上传进度.

What you might want to do instead is do AJAX uploading, using something like DropzoneJS on the frontend (and still use Stapler on the backend). This way users can upload 1->many files, and see the progress of their upload.

您可以做的是,上传完成后,您可以将图像调整大小后排队在S3内进行-这样可能会使速度更快一些.

What you can then do is once the upload is complete, you can queue the image resizing to occur inside S3 - that might make it a little faster.

这篇关于在Laravel中实现图像处理的队列-要排队什么而不要排队什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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