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

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
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi
Shift logo

Shift

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

Shift
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
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
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Laravel Cloud logo

Laravel Cloud

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

Laravel Cloud
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
Lucky Media logo

Lucky Media

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

Lucky Media
Tinkerwell logo

Tinkerwell

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

Tinkerwell
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
PhpStorm logo

PhpStorm

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

PhpStorm

The latest

View all →
Clonio CLI: Clone Production Databases With Anonymized Data image

Clonio CLI: Clone Production Databases With Anonymized Data

Read article
Ship AI with Laravel: Test Your AI System with Zero API Calls image

Ship AI with Laravel: Test Your AI System with Zero API Calls

Read article
Laravel WhatsApp: Two Backends Behind One Facade image

Laravel WhatsApp: Two Backends Behind One Facade

Read article
Turn PHP Attributes Into Docs With Signal image

Turn PHP Attributes Into Docs With Signal

Read article
USAIGE: Track Token Usage and Costs for Laravel AI SDK Requests image

USAIGE: Track Token Usage and Costs for Laravel AI SDK Requests

Read article
Help make Filament faster! image

Help make Filament faster!

Read article