Performance: Dispatching jobs
HIGH IMPACT
This affects how quickly the main web request responds by offloading work to background processes, improving user experience and server responsiveness.
<?php
use App\Jobs\ProcessLargeFile;
public function store(Request $request) {
ProcessLargeFile::dispatch($request->file);
return response()->json(['status' => 'queued']);
}
// Job class handles processing asynchronously<?php
// Controller method
public function store(Request $request) {
// Heavy task directly in request
$this->processLargeFile($request->file);
return response()->json(['status' => 'done']);
}
private function processLargeFile($file) {
// Simulate heavy processing
sleep(10);
// Process file logic
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous heavy task in request | N/A | Blocks main thread | Delays paint | [X] Bad |
| Dispatch job to queue | N/A | No blocking | Fast paint | [OK] Good |