Worker Metrics on the WorkerStopping Event in Laravel 13.18

Last updated on by

Worker Metrics on the WorkerStopping Event in Laravel 13.18 image

Never Miss a Laravel Release 🚀

Sign up and get an email with each new Laravel release

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.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Laravel Code Review

Get expert guidance in a few days with a Laravel code review

Visit Laravel Code Review
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing

The latest

View all →
Laravel Time Machine: A Request Lifecycle Profiler image

Laravel Time Machine: A Request Lifecycle Profiler

Read article
Laravel SMS Catcher: A Local Dashboard for SMS Notifications image

Laravel SMS Catcher: A Local Dashboard for SMS Notifications

Read article
The Analytics Stack for Laravel: Traffic, Revenue and Attribution in One Place image

The Analytics Stack for Laravel: Traffic, Revenue and Attribution in One Place

Read article
Scaffold Packages with the `laravel package` Command in Laravel Installer v5.31.0 image

Scaffold Packages with the `laravel package` Command in Laravel Installer v5.31.0

Read article
Vocalizer: Local Text-to-Speech for PHP image

Vocalizer: Local Text-to-Speech for PHP

Read article
Build a Laravel Scout Search Endpoint With the HTTP QUERY Method image

Build a Laravel Scout Search Endpoint With the HTTP QUERY Method

Read article