help with what?
Jan 28, 2017
7
Level 3
Laravel Job -> Stuck in loop, MySQL gone away in logs.
Hi Guys,
Hope you're well, I'm having a little issue with a job I've created. The job resizes images that I've uploaded to the application.
Here is the job:
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Image;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class resizeImages extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
protected $img;
protected $destinationPath;
protected $filename;
protected $uploadcount;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($img,$destinationPath,$filename,$uploadcount)
{
$this->img = $img;
$this->destinationPath = $destinationPath;
$this->filename = $filename;
$this->uploadcount = $uploadcount;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// crop the best fitting 5:3 (600x360) ratio and resize to 600x360 pixel
// backup status
echo 'make backup';
$img = Image::make($this->img);
$img->backup();
// perform some modifications
echo 'start 1';
$img->fit(1024, 768);
$img->save($this->destinationPath.'/'.'1024x768-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 2';
$img->fit(1152, 864);
$img->save($this->destinationPath.'/'.'1152x864-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 3';
$img->fit(1208, 720);
$img->save($this->destinationPath.'/'.'1208x720-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 4';
$img->fit(1280, 800);
$img->save($this->destinationPath.'/'.'1280x800-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 5';
$img->fit(1280, 960);
$img->save($this->destinationPath.'/'.'1280x960-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 6';
$img->fit(1280, 1024);
$img->save($this->destinationPath.'/'.'1280x1024-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 7';
$img->fit(1366, 768);
$img->save($this->destinationPath.'/'.'1366x768-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 8';
$img->fit(1440, 900);
$img->save($this->destinationPath.'/'.'1440x900-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 9';
$img->fit(1600, 1200);
$img->save($this->destinationPath.'/'.'1600x1200-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 10';
$img->fit(1680, 1050);
$img->save($this->destinationPath.'/'.'1680x1050-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 11';
$img->fit(1920, 1080);
$img->save($this->destinationPath.'/'.'1920x1080-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 12';
$img->fit(1920, 1200);
$img->save($this->destinationPath.'/'.'1920x1200-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 13';
$img->fit(2048, 1536);
$img->save($this->destinationPath.'/'.'2048x1536-'.$this->filename);
// reset image (return to backup state)
echo 'reset';
$img->reset();
// perform other modifications
echo 'start 14';
$img->fit(2560, 1600);
$img->save($this->destinationPath.'/'.'2560x1600-'.$this->filename);
echo 'finish 14';
}
}
Any help would be great.
Please or to participate in this conversation.