Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将多个图像大小调整操作委托给Laravel作业不会加快上载过程_Php_Laravel_Performance_Laravel 5_Intervention - Fatal编程技术网

Php 将多个图像大小调整操作委托给Laravel作业不会加快上载过程

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

在我们的平台上上传图片时,我一直在尝试优化用户体验或管理员体验。这些图像相当重(7-10MB),一次上传3个,异步(使用)。每个图像都以多种大小存储,使用

原始逻辑

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