Php 将多个图像大小调整操作委托给Laravel作业不会加快上载过程
在我们的平台上上传图片时,我一直在尝试优化用户体验或管理员体验。这些图像相当重(7-10MB),一次上传3个,异步(使用)。每个图像都以多种大小存储,使用 原始逻辑Php 将多个图像大小调整操作委托给Laravel作业不会加快上载过程,php,laravel,performance,laravel-5,intervention,Php,Laravel,Performance,Laravel 5,Intervention,在我们的平台上上传图片时,我一直在尝试优化用户体验或管理员体验。这些图像相当重(7-10MB),一次上传3个,异步(使用)。每个图像都以多种大小存储,使用 原始逻辑 <?php $file = $request->file('qqfile'); // A big JPG file in the request $image = Image::make($file); // Building an Intervention Image object $siz
<?php
$file = $request->file('qqfile'); // A big JPG file in the request
$image = Image::make($file); // Building an Intervention Image object
$sizes = array(2560, 1980, 1366, 1024, 768, 480, 320);
foreach ($sizes as $size) {
$image = $image->widen($size->width);
Storage::put('public/image_'.$size.'.jpg', $image->encode('jpg', 90));
// image_2560.jpg, image_1980.jpg, etc.
}
首先,确保确实使用了Redis
作为队列驱动程序。确保在.env
中设置了它,确保它未缓存在配置文件中(运行php-artisan-config:clear
或php-artisan-config:cache
)。另外,如果您的队列工作程序正在运行,请确保已重新启动它
如果不是这样,你应该确定上传的时间和调整图片大小的时间。你确定上传不需要13分钟,调整大小只需要2分钟吗?你通过php artisan config:clear
:)中了大奖,我所需要做的就是将它添加到部署脚本中。太棒了。@Lessugar很高兴我能帮忙:)
<?php
$file = $request->file('qqfile'); // A big JPG file in the request
$image = Image::make($file); // Building an Intervention Image object
$sizes = array(2560, 1980, 1366, 1024, 768, 480, 320);
foreach ($sizes as $size) {
if ($size == 2560) {
// Store the biggest size: image_2560.jpg
$image = $image->widen($size->width);
Storage::put('public/image_'.$size.'.jpg', $image->encode('jpg', 90));
} else {
// Delegate the job to store a resized image, 15 minutes from now
ProcessImageStoring::dispatch($size)->delay(Carbon::now()->addMinutes(15));
}
}