News

Worker Metrics on the WorkerStopping Event in Laravel 13.18

Published
Worker Metrics on the WorkerStopping Event in Laravel 13.18 image

Release updates

Never miss a Laravel release

Get an email whenever a new Laravel release lands.

Laravel 13.18.0 adds worker metrics to the WorkerStopping event, graceful signal handling for schedule:work, priority-based registration for artisan dev commands, and a batch of fixes across the Number helpers, cache, and scheduler.

  • Jobs-processed count and last-job timestamp on the WorkerStopping event
  • schedule:work now catches termination signals and finishes in-flight runs
  • Priority-based registration for dev commands, plus --kill-others-on-fail for artisan dev
  • Number::forHumans(), Number::abbreviate(), and Number::fileSize() no longer crash on INF/NAN
  • Conditional return types and getter/property generic sync across several methods
  • Fixes for HEAD request cache headers, debounced job cache reads, and TaggedCache label collisions

What's New

Worker Metrics on the WorkerStopping Event

The WorkerStopping event now carries two extra values describing what the worker did before it shut down: jobsProcessed, the number of jobs the worker handled during its lifetime, and lastJobProcessedAt, a microtime timestamp of the final job it processed. Both are populated whether the worker stops normally or is killed.

use Illuminate\Queue\Events\WorkerStopping;
 
Event::listen(function (WorkerStopping $event) {
$event->jobsProcessed; // int|null
$event->lastJobProcessedAt; // int|float|null (microtime), null if nothing was processed
});

This gives you a place to record per-worker throughput or emit metrics when a daemon exits, without instrumenting the job loop yourself. When a worker stops before processing anything, lastJobProcessedAt stays null.

See #60592 and the follow-up in #60608.

Graceful Shutdown for schedule:work

The schedule:work command now catches SIGINT, SIGTERM, and SIGQUIT. On receiving a signal it stops starting new scheduled runs and waits for any in-progress schedule:run to finish before exiting, mirroring the existing behavior of queue:work. This matters in container environments like Kubernetes, where pods receive SIGTERM on shutdown and the previous behavior could interrupt a running task.

See #60616.

Priority-Based Dev Command Registration

Dev commands registered for artisan dev now track where they came from (your application, a vendor package, or the framework) and register with a matching priority. When more than one command shares a name, userland registrations win over vendor ones, which win over framework defaults, regardless of service provider boot order.

use Illuminate\Foundation\Console\DevCommands;
 
DevCommands::artisan('reverb:start --host="0.0.0.0"', 'reverb');

This replaces the vendor auto-registration blocker approach with explicit priority, so your overrides always take effect. Related, artisan dev now runs with --kill-others-on-fail, so if one process in the group fails the rest are stopped instead of left running.

See #60580 and #60606.

Number Helpers Hardened Against INF/NAN

Number::forHumans() and Number::abbreviate() previously crashed when passed INF or NAN, and Number::fileSize() had the same problem. Both are fixed so these inputs are handled without throwing.

See #60617 and #60625.

Other Fixes and Improvements

  • Further reduced cache hits when using debounced jobs (#60575)
  • Fixed cache headers not being set on HEAD requests (#60589)
  • Prevented the restored event from firing when a soft-delete restore fails (#60605)
  • Fixed the RateLimited middleware not serializing releaseAfter in __sleep() (#60609)
  • Fixed flexible() lock and defer label collisions in TaggedCache (#60626)
  • Fixed JSON parsing for top-level zero bodies (#60614)
  • Added conditional return types to several methods (#60586) and synced getter return types with their property generics (#60591)

References

Paul Redmond photo

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

Sponsored

serpapi logo
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi

The latest

View all →
Laravel Truss: Live Interactive Database ER Diagrams image

Laravel Truss: Live Interactive Database ER Diagrams

Read article
Laravel artisan dev: Run Server, Queue, Logs, and Vite image

Laravel artisan dev: Run Server, Queue, Logs, and Vite

Read article
Validate and Convert HEIC Images in Laravel image

Validate and Convert HEIC Images in Laravel

Read article
Saga Lara Flow: Durable Workflows and Compensating Transactions on Laravel Queues image

Saga Lara Flow: Durable Workflows and Compensating Transactions on Laravel Queues

Read article
Reject Unexpected Array Keys with Laravel Validation image

Reject Unexpected Array Keys with Laravel Validation

Read article
Major performance improvements & security patches for Filament v4.12 and v5.7! image

Major performance improvements & security patches for Filament v4.12 and v5.7!

Read article