Performance: Queue configuration
MEDIUM IMPACT
Queue configuration affects how background jobs are processed, impacting server response time and user experience by offloading tasks from the main request cycle.
<?php
use IlluminateContractsQueueShouldQueue;
// Dispatch job to queue
public function upload(Request $request) {
$image = $request->file('image');
ProcessImageJob::dispatch($image->path());
return response()->json(['status' => 'queued']);
}
// Job class handles resizing asynchronously
class ProcessImageJob implements ShouldQueue {
public $path;
public function __construct($path)
{
$this->path = $path;
}
public function handle() {
$image = Image::make($this->path)->resize(2000, 2000)->save();
}
}
<?php
// In controller
public function upload(Request $request) {
// Process file upload and heavy image resizing synchronously
$image = $request->file('image');
$resized = Image::make($image)->resize(2000, 2000)->save();
return response()->json(['status' => 'done']);
}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous heavy task in request | Minimal | N/A | Blocks paint until task completes | [X] Bad |
| Asynchronous queue job processing | Minimal | N/A | Paints quickly, task runs in background | [OK] Good |