Next-Level Performance: Mastering Laravel 12.34 and 12.35 New Features
Overview
Prerequisites
To follow along, you should have a solid grasp of:
- PHP 8.2 or higher
- Basic understanding of the Laravel Service Container and Queues
- Familiarity with
config/cache.phpandconfig/queue.phpstructures
Key Libraries & Tools
- Laravel Framework: The core PHP framework receiving these updates.
- Redis: Often used as the primary driver for both caching and queuing.
- Laravel Herd: A local development environment used to demonstrate service management.
The Deferred Queue Connection
One of the most impactful additions is the deferred queue connection. Unlike the standard sync driver—which blocks the user's browser until the job finishes—the deferred driver processes the job immediately after the HTTP response is sent to the client.
// In your Controller
ProcessNewPost::dispatch($post)->onConnection('deferred');
return redirect()->route('posts.index');
By switching to the deferred connection, the user sees an immediate redirect, while the "heavy" logic runs in the background. This provides the speed of an asynchronous worker without needing to configure a separate daemon for local development.
Implementing Failover Strategies
Systems fail. failover driver for both
// config/cache.php
'stores' => [
'failover' => [
'driver' => 'failover',
'stores' => ['redis', 'database', 'array'],
],
]
Syntax Notes
- Fluent Configuration: The
failoverdriver expects a prioritized list of stores in thestoresarray. - Driver Switching: You must update your
.envfile (e.g.,CACHE_STORE=failover) to activate these strategies.
Tips & Gotchas
- Persistence: Remember that the
arraycache driver is not persistent across requests; usedatabaseas a secondary fallback if data persistence is required duringRedisoutages. - Debugging: When using the
deferredconnection, useLog::info()to verify job completion since you won't see errors in the browser once the response is sent.
