Skip to content
Back to blog
Laravel Updates4 min read

Laravel 13.45: Migration durations, job memory usage and stricter SVG validation

With Laravel 13.45, you can read how long migrations take and how much memory queue jobs use straight from events. The database cache gets batched writes, and there are security fixes for SVG uploads and the trusted proxy setting.

Laravel 13.45: Migration durations, job memory usage and stricter SVG validation

Laravel 13.45.0 is out. This release brings two new measurements: migration duration and per-job memory usage. On top of that, there is a performance improvement for the database cache and two security fixes. One of the security fixes can change how your existing validation rules behave, so be sure to read that section before upgrading.

Migration duration on the MigrationEnded event

The MigrationEnded event now has a duration property. It holds how many milliseconds the migration took and is filled in for both up and down. A single listener is enough to catch slow migrations:

use Illuminate\Database\Events\MigrationEnded;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;

Event::listen(function (MigrationEnded $event) {
    // Log migrations that take longer than a minute
    if ($event->duration > 60_000) {
        Log::warning("Slow migration: {$event->name} ({$event->duration} ms)");
    }
});

Laravel 13.42 already added events for failed migrations. Used together, they let you keep an eye on both slow and failed migrations. (Contributed by Jack Bayliss, #62605)

Peak memory usage on the JobAttempted event

The JobAttempted event now has a memoryUsage property. It reports the peak memory usage the worker reached while processing the job, in megabytes:

use Illuminate\Queue\Events\JobAttempted;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;

Event::listen(function (JobAttempted $event) {
    Log::info($event->job->resolveName(), [
        'duration' => $event->duration,
        'memory_mb' => $event->memoryUsage,
    ]);
});

Two details matter here. The event fires whether the job succeeds or fails. The worker also resets PHP's peak memory counter before each job, so the value applies to that single job, not to the whole lifetime of the worker. (Contributed by Jack Bayliss, #62678)

Batched writes and deletes for the database cache

In the database cache driver, putMany() called without a TTL and deleteMultiple() no longer run a separate query for every key. Keys are now written and deleted in groups of 250 per query:

// 600 keys: 3 queries instead of 600
Cache::store('database')->putMany($values);

Cache::store('database')->deleteMultiple($keys);

The group size was chosen to stay below SQL Server's limit of 2,100 parameters per query. In the PR's benchmark on SQL Server 2022, writing 3,000 keys dropped from 3,514 ms to 146 ms. This change follows the Redis pipelining improvement in Laravel 13.44. (Contributed by Rias, #62626)

Behavior change: the dimensions rule requires SVG to be allowed explicitly

Until this release, the dimensions rule let SVG files through without checking them at all. That meant a field validated only with dimensions could accept an SVG containing JavaScript. Now an SVG passes the dimensions rule only if another rule on the same field allows SVG:

// Now fails for an SVG upload
'avatar' => ['dimensions:max_width=1000'],

// Passes for an SVG upload
'avatar' => ['image:allow_svg', 'dimensions:max_width=1000'],
'avatar' => ['mimes:png,jpg,svg', 'dimensions:max_width=1000'],

If you have fields that should accept SVG and use dimensions, add image:allow_svg, a mimes rule that includes svg, or a mimetypes rule that includes image/svg+xml. (Contributed by Mior Muhammad Zaki, #62716)

Wildcard trusted proxies trust only the calling proxy

An earlier change made the trustProxies(at: '*') setting trust every address in the X-Forwarded-For header. As a result, the left-most address, which the client can write itself, was accepted as the client IP, leaving the door open to IP spoofing. That change has been reverted:

->withMiddleware(function (Middleware $middleware) {
    $middleware->trustProxies(at: '*');
})

As in v13.19.0, this setting now trusts only the proxy connecting directly to the server (REMOTE_ADDR). (Contributed by Mior Muhammad Zaki, #62702)

Request::prefetch() now recognizes prerender requests

Chrome sends the Sec-Purpose: prefetch;prerender header on prerender requests made through the Speculation Rules API. Until now, the prefetch() method only recognized the exact value prefetch:

// Sec-Purpose: prefetch;prerender
$request->prefetch(); // now true (previously false)

This has a practical effect: the session middleware uses this method to keep prefetched URLs from being stored as the "previous URL". Before the fix, back() could redirect to a page the user never opened, one that had only been prerendered. (Contributed by Emaia, #62665)

Other notable changes

  • MAC validation during decryption is now performed across all decryption keys (#62628).

  • Request::isJson() is now case-insensitive (#62701).

  • Fixed the not_in rule accepting numerically equal values and arrays (#62703).

  • Fixed the doesnt_contain rule accepting typed values (#62704).

  • trustHosts() respects the subdomains option when no hosts are given (#62677).

  • Fixed incorrect read replica details shown in query exceptions (#62710).

  • Fixed response compatibility with Symfony 8.2 (#62654).

  • route:list output now takes the on-screen width of characters into account when aligning (#62709).

For the full list of changes, see the 13.44.0 → 13.45.0 comparison on GitHub.


Sources