News

Migration Durations and Job Memory Usage in Laravel 13.45

Published
Migration Durations and Job Memory Usage in Laravel 13.45 image

The Laravel team released v13.45.0 with a migration duration on the MigrationEnded event, peak memory usage on the JobAttempted event, batched writes for the database cache store, and security fixes for SVG uploads and trusted proxies:

Migration Duration on the MigrationEnded Event

Jack Bayliss added a duration property to the MigrationEnded event. It holds the number of milliseconds a migration took to run, for both up and down:

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

Event::listen(function (MigrationEnded $event) {
    if ($event->duration > 60_000) {
        Log::warning("Migration [{$event->name}] took {$event->duration}ms.");
    }
});

A listener like this can warn you when one migration uses most of a deployment window. Laravel 13.42 added migration failure events, so you can now listen for both slow and failed migrations.

See #62605 for more details.

Peak Memory Usage on the JobAttempted Event

Jack Bayliss also added a memoryUsage property to the JobAttempted event. It holds the worker's peak memory usage in megabytes while it processed the job:

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' => $event->memoryUsage,
    ]);
});

The queue worker dispatches JobAttempted whether the job succeeds or fails, and it resets PHP's peak memory counter before each job. The value is for one job, not for the lifetime of the worker.

See #62678 for more details.

Batched Writes and Deletes for the Database Cache Store

Rias changed the database cache store so that putMany() without a TTL and deleteMultiple() no longer run one query per key. Laravel now writes or deletes 250 keys per query:

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

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

The chunk size keeps each query under the 2,100 bound parameter limit on SQL Server. In the pull request, writing 3,000 keys on SQL Server 2022 went from 3,514 ms to 146 ms. This follows the Redis pipelining change in Laravel 13.44.

See #62626 for more details.

The dimensions Rule Requires SVG to Be Allowed Explicitly

Mior Muhammad Zaki changed how the dimensions validation rule handles SVG files. Before this release, the rule passed any SVG upload without checking it, so a field validated with only dimensions accepted an SVG that contained JavaScript.

An SVG now passes dimensions only when another rule on the same attribute allows SVG:

// 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'],

This is a behavior change. If your application accepts SVG uploads on a field that uses dimensions, check that the field also has image:allow_svg, a mimes rule that includes svg, or a mimetypes rule that includes image/svg+xml.

See #62716 for more details.

Wildcard Trusted Proxies Trust Only the Calling Proxy

Mior Muhammad Zaki reverted an earlier change to trustProxies(at: '*'). That change made the wildcard trust every address in the X-Forwarded-For header, so the left-most entry, which the client can set, became the client IP. An application that used the wildcard could have its client IP spoofed.

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

With this release, the wildcard trusts only the proxy that calls your server (REMOTE_ADDR), as it did in v13.19.0.

See #62702 for more details.

Prerender Requests in Request::prefetch()

Emaia updated Request::prefetch() to recognize prerender requests. Chrome sends Sec-Purpose: prefetch;prerender for pages prerendered through the Speculation Rules API, and the method only matched the exact value prefetch:

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

Laravel's session middleware uses this check to keep prefetched URLs out of the session's previous URL. Without the fix, back() could redirect to a prerendered page the user never opened.

See #62665 for more details.

Release Notes

You can see the complete list of new features and updates below and the diff between 13.44.0 and 13.45.0 on GitHub.

v13.45.0

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in

Sponsored

serpapi logo
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi

The latest

View all →
Laravel CLI: One Binary for New PHP and Rust Laravel Apps image

Laravel CLI: One Binary for New PHP and Rust Laravel Apps

Read article
Phactorial: Render LaTeX Math to SVG and PNG in PHP image

Phactorial: Render LaTeX Math to SVG and PNG in PHP

Read article
Laravel, reimagined image

Laravel, reimagined

Read article
Laravel Rust: A New Rust Web Framework From Laravel image

Laravel Rust: A New Rust Web Framework From Laravel

Read article
Laravel Converse and Agent Kit for Chat Bots and AI Agents image

Laravel Converse and Agent Kit for Chat Bots and AI Agents

Read article
Test Tool Approval Flows in the Laravel AI SDK image

Test Tool Approval Flows in the Laravel AI SDK

Read article