简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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