Laravel 5:执行异步任务


Laravel 5: Performing an asynchronous task

我有以下函数,其中我处理类型为UploadedFile的图像文件,将其作为随机名称,使用'Intervention'Image以不同的大小存储它,然后返回图像名称。

存储部分需要花费大量时间,并且请求通常会超时。如果我能在单独的线程或进程中进行处理,并返回图像名称,那就太好了。下面是我的代码:

public function storeSnapshots(UploadedFile $image) {
    // Generate a random image name.
    $imageName = str_random(12) . '.' . $image->getClientOriginalExtension();
    // Process the image. Should be done asynchronously.
    'Intervention'Image'Facades'Image::make($image)
        ->heighten(2000, function($constraint) {
            $constraint->upsize();
        })->save('img/lg/' . $imageName)
        ->heighten(800)->save('img/md/' . $imageName)
        ->heighten(120)->save('img/sm/' . $imageName);
    // Return the image name generated.
    return $imageName;
}

Laravel执行异步任务的方式是什么?

Laravel通过队列系统执行异步任务。