Implementing queue for image processing in Laravel - what to queue and what not to?

主宰稳场 提交于 2020-02-07 05:33:06

问题


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);
    }   

}

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?


回答1:


You cant queue the 'upload' process.

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.

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.



来源:https://stackoverflow.com/questions/29581810/implementing-queue-for-image-processing-in-laravel-what-to-queue-and-what-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!