<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hafiz</title>
    <description>The latest articles on DEV Community by Hafiz (@hafiz619).</description>
    <link>https://dev.to/hafiz619</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1284090%2F71b229af-8e87-4b83-8e79-e5176a1f561e.png</url>
      <title>DEV Community: Hafiz</title>
      <link>https://dev.to/hafiz619</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hafiz619"/>
    <language>en</language>
    <item>
      <title>Laravel Rust vs Laravel PHP: I Repeated the Official Benchmark on Hetzner</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Wed, 02 Dec 2026 15:39:03 +0000</pubDate>
      <link>https://dev.to/hafiz619/laravel-rust-vs-laravel-php-i-repeated-the-official-benchmark-on-hetzner-3ghe</link>
      <guid>https://dev.to/hafiz619/laravel-rust-vs-laravel-php-i-repeated-the-official-benchmark-on-hetzner-3ghe</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/laravel-rust-vs-php-benchmark-hetzner" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;On 1 December, Laravel published &lt;a href="https://laravel.com/blog/laravel-rust-benchmark" rel="noopener noreferrer"&gt;a benchmark&lt;/a&gt; of Laravel Rust, its new full stack Rust framework. The post's title puts it at 18 times the throughput of Laravel PHP. Sam Rose ran it on Laravel Cloud, put both apps and the k6 script &lt;a href="https://github.com/laravel/laravel-framework-benchmarking-2026" rel="noopener noreferrer"&gt;on GitHub&lt;/a&gt;, and asked readers to get in touch if they found mistakes in his testing.&lt;/p&gt;

&lt;p&gt;So I ran it again, on servers I rented by the hour from Hetzner. Same apps, same k6 script (checked against the official file's SHA-256), and MySQL 8.4 like the original. Then I added the two setups a lot of us actually run: nginx with PHP-FPM, and a €7 VPS with everything on one box. That came to 34 measured runs (plus 3 setup checks) and about €2 of servers, all deleted afterwards.&lt;/p&gt;

&lt;p&gt;Laravel Rust served 11 to 13 times what Octane did on every server I tried. Not 18. But the gap survived every change I made.&lt;/p&gt;

&lt;h2&gt;
  
  
  The results
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Server&lt;/th&gt;
&lt;th&gt;Laravel Rust&lt;/th&gt;
&lt;th&gt;Octane + FrankenPHP&lt;/th&gt;
&lt;th&gt;nginx + PHP-FPM&lt;/th&gt;
&lt;th&gt;Rust vs Octane&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1 dedicated vCPU, 4 GiB&lt;/td&gt;
&lt;td&gt;1,991.4 (hit the cap)&lt;/td&gt;
&lt;td&gt;166.9&lt;/td&gt;
&lt;td&gt;92.5&lt;/td&gt;
&lt;td&gt;at least 11.9×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;€7 VPS, 2 shared vCPU, 4 GB&lt;/td&gt;
&lt;td&gt;1,012.6&lt;/td&gt;
&lt;td&gt;90.3&lt;/td&gt;
&lt;td&gt;61.9&lt;/td&gt;
&lt;td&gt;11.2×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Same VPS booted as 1 vCPU, 961 MiB&lt;/td&gt;
&lt;td&gt;562.3&lt;/td&gt;
&lt;td&gt;44.5&lt;/td&gt;
&lt;td&gt;31.0&lt;/td&gt;
&lt;td&gt;12.6×&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The numbers are requests per second in the best 10-second window with no failed request, which is the official method. Both VPS rows are the median of three rounds. On the dedicated vCPU, MySQL ran on its own server. On the VPS, nginx, the app and MySQL shared the box.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-rust-vs-php-benchmark-hetzner" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For reference, Laravel's run on Cloud measured 1,774 requests per second for Laravel Rust and 97 for Laravel PHP, which is Octane on FrankenPHP.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I tested
&lt;/h2&gt;

&lt;p&gt;Four servers in Hetzner's Helsinki region, all on Ubuntu 24.04 and a private network, behind a firewall that only lets SSH in. A spread placement group put each one on a different physical host.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Server&lt;/th&gt;
&lt;th&gt;Hetzner type&lt;/th&gt;
&lt;th&gt;Job&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;bench-k6&lt;/td&gt;
&lt;td&gt;ccx13, 2 dedicated vCPU, 8 GB&lt;/td&gt;
&lt;td&gt;k6 2.3.0, the same size as Laravel's load generator&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bench-db&lt;/td&gt;
&lt;td&gt;ccx13, 2 dedicated vCPU, 8 GB&lt;/td&gt;
&lt;td&gt;MySQL 8.4.13 for the dedicated test&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bench-app&lt;/td&gt;
&lt;td&gt;ccx23, 4 dedicated vCPU (AMD EPYC Milan), 16 GB&lt;/td&gt;
&lt;td&gt;the app on one vCPU, nginx on another core&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bench-vps&lt;/td&gt;
&lt;td&gt;cx23, 2 shared vCPU (Intel Xeon Skylake), 4 GB&lt;/td&gt;
&lt;td&gt;nginx, app and MySQL together&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Laravel Cloud gave each app a container with 1 vCPU and 4 GiB. On a VPS, the same budget takes two systemd drop-ins. Each app's service joins a slice with a memory cap and gets pinned to vCPU 0:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c1"&gt;# /etc/systemd/system/benchapp.slice.d/50-limits.conf
&lt;/span&gt;&lt;span class="k"&gt;[Slice]&lt;/span&gt;
&lt;span class="na"&gt;MemoryMax&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4G&lt;/span&gt;
&lt;span class="na"&gt;MemorySwapMax&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="c1"&gt;# /etc/systemd/system/bench-rust.service.d/50-bench.conf
&lt;/span&gt;&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Slice&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;benchapp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;slice&lt;/span&gt;
&lt;span class="na"&gt;CPUAffinity&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Octane and PHP-FPM services got the same drop-in. Versions: Laravel Rust 0.1.0 built with Rust 1.99.1, FrankenPHP 1.13.6 with PHP 8.5.13, PHP-FPM 8.5 from packages.sury.org and MySQL 8.4.13. From the official README I copied &lt;code&gt;OCTANE_WORKERS=4&lt;/code&gt;, &lt;code&gt;DB_MAX_CONNECTIONS=20&lt;/code&gt; for Rust and &lt;code&gt;APP_ENV=production&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;PHP-FPM ran &lt;code&gt;pm = static&lt;/code&gt;, with OPcache on and &lt;code&gt;validate_timestamps=0&lt;/code&gt;. I picked its worker count by testing. With 4, 8 and 16 workers, all three were overloaded at 150 requests per second, and 8 had the fewest failures. The 2 vCPU VPS ran 16 workers, and the 1 vCPU boot ran 8.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I changed, and why
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;gzip moved to nginx.&lt;/strong&gt; Cloud's edge compresses responses, and neither app compresses by itself, except Octane's Caddyfile, which has &lt;code&gt;encode @compressible zstd br gzip&lt;/code&gt;. So nginx did the compression (on its own vCPU on the dedicated box) and stripped &lt;code&gt;Accept-Encoding&lt;/code&gt; before passing requests on. I also ran Octane once with compression inside the app. It served 156 requests per second instead of 167, about 7% less.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No TLS in front of the app.&lt;/strong&gt; k6 sent plain HTTP over the private network. Laravel's run went through a public HTTPS hostname, so my latencies are lower in absolute terms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TLS to MySQL on the dedicated test.&lt;/strong&gt; Laravel Rust's driver (sqlx 0.9, built without its &lt;code&gt;rsa&lt;/code&gt; feature) can't log in to MySQL 8.4 over plain TCP. So both apps reached bench-db over TLS with a verified certificate. On the VPS, both used the Unix socket.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FrankenPHP pinned to 1.13.6.&lt;/strong&gt; By default Octane downloads the latest FrankenPHP release. That was 1.14.0, which ships PHP 8.6.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A shorter ramp for PHP.&lt;/strong&gt; The official ramp climbs from 1 to 2,000 requests per second over 20 minutes. Octane's first run got the full ramp and never passed 167, so the later PHP runs used the same slope and stopped at 500. Rust always got the full ramp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Laravel's result holds, at 11 to 13× instead of 18×
&lt;/h2&gt;

&lt;p&gt;Laravel Rust climbed the whole 20-minute ramp without a single failed request, 1,200,442 successful responses in total. Its best window came at 19 minutes 50 seconds, with 1,991 requests per second and a p95 of 44 ms. The app itself peaked at 56% of its vCPU.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi3p4c9yy6cwgz09p844a.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi3p4c9yy6cwgz09p844a.webp" alt="k6 report for Laravel Rust on one dedicated vCPU. The request rate climbs steadily to 2,000 per second, the p95 line stays low apart from one spike, and the failure line stays at zero." width="799" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That 1,991 is a floor, not Rust's ceiling. The official ramp stops at 2,000, and by then the k6 server was close to 100% CPU. Over the run, k6 couldn't start 138 of its scheduled requests (none in the best window). So the real limit of Laravel Rust on one EPYC vCPU is somewhere above 2,000, and I didn't measure it.&lt;/p&gt;

&lt;p&gt;Octane went the other way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnmey1yse9i2jy9abcrid.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnmey1yse9i2jy9abcrid.webp" alt="k6 report for Octane with FrankenPHP on one dedicated vCPU. The request rate climbs to about 180 per second, then the p95 line jumps to the 5-second timeout and failures sit near 100% for the rest of the run." width="799" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Its best clean window came at 1 minute 50 seconds, with 167 requests per second and a p95 of 1.5 seconds. Thirty seconds later requests started failing, and they kept failing until the end. Over the 20 minutes, Octane completed 21,729 requests and 309,920 timed out. Not one was a 5xx error. Every failure was k6 giving up after 5 seconds. The flat line near 300 per second in the chart is what 1,500 virtual users (the script's cap) produce when each one waits out a 5-second timeout.&lt;/p&gt;

&lt;p&gt;So why 11 to 13× and not 18×? On my dedicated vCPU, Octane did better than on Cloud (167 against 97), while Rust ran into the ramp's ceiling. I can't tell you exactly why Octane was faster here. The CPUs differ, my requests skipped TLS and Cloud's edge, and the region is different. But the ratio barely moved across three very different servers (11.9, 11.2 and 12.6).&lt;/p&gt;

&lt;p&gt;PHP-FPM came last everywhere. Octane served 1.4 to 1.8 times as much on the same box.&lt;/p&gt;

&lt;h2&gt;
  
  
  On a small VPS, the whole machine is the limit
&lt;/h2&gt;

&lt;p&gt;On the €7 VPS, nginx, MySQL and the app compete for the same two shared vCPUs. During Rust's runs the app peaked at about 120% of one vCPU, MySQL at 60% and nginx at 22%. That adds up to the whole box, which hit 99% CPU. So 1,013 is the limit of this VPS with Rust on it, not the limit of Rust.&lt;/p&gt;

&lt;p&gt;The 1 vCPU boot shows the same thing with memory. I started the same VPS with &lt;code&gt;maxcpus=1 mem=1G&lt;/code&gt;, which leaves 961 MiB, and recorded htop for a minute, starting 3 minutes into each ramp. This is Rust:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffn8c99ylbfs4gdfrke22.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffn8c99ylbfs4gdfrke22.webp" alt="htop on the 1 vCPU, 961 MiB VPS during the Laravel Rust ramp. The CPU is at 75%, chirper-laravel-rust uses 39.4% CPU and 24 MB of resident memory, and mysqld holds 486 MB, half of the machine's memory." width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Rust binary used 24 MB of resident memory. MySQL used 486 MB, half the machine. On a box this size, the database is the heavy process, whatever language the app is written in.&lt;/p&gt;

&lt;p&gt;Octane at the same point in its ramp had the CPU at 100%, with FrankenPHP using 192 MB:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvd6cawi06zdy0ip1d6td.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvd6cawi06zdy0ip1d6td.webp" alt="htop during the Octane ramp on the same 1 vCPU box. The CPU is at 100%, frankenphp uses 81.9% CPU and 192 MB of resident memory, and mysqld holds 476 MB." width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Past its limit, PHP falls over instead of slowing down
&lt;/h2&gt;

&lt;p&gt;The steady test sends 50 requests per second for 5 minutes. On the 1 vCPU, 961 MiB VPS, that's above both PHP limits (44.5 and 31). The result isn't a gentle slowdown:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;50 req/s on 1 vCPU, 961 MiB&lt;/th&gt;
&lt;th&gt;Served per second&lt;/th&gt;
&lt;th&gt;Failed&lt;/th&gt;
&lt;th&gt;p95 over the run&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Laravel Rust&lt;/td&gt;
&lt;td&gt;50.0&lt;/td&gt;
&lt;td&gt;0.0%&lt;/td&gt;
&lt;td&gt;17 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Octane + FrankenPHP&lt;/td&gt;
&lt;td&gt;16.6&lt;/td&gt;
&lt;td&gt;66.7%&lt;/td&gt;
&lt;td&gt;4,995 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;nginx + PHP-FPM&lt;/td&gt;
&lt;td&gt;1.2&lt;/td&gt;
&lt;td&gt;97.6%&lt;/td&gt;
&lt;td&gt;4,759 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;At its limit, Octane served 44.5 requests per second. Pushed 5.5 past it, it served 16.6. Once requests wait longer than the client does, the server spends its CPU on responses nobody will read, and new requests queue behind them.&lt;/p&gt;

&lt;p&gt;The PHP-FPM worker test on the dedicated box shows the same pattern. With 4 workers at 150 requests per second, the best 10-second window served 86 per second. Averaged over the 3-minute hold, it served 7.1.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Focdp13lfn4ba23bjl3k1.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Focdp13lfn4ba23bjl3k1.webp" alt="htop during the PHP-FPM ramp on the 1 vCPU box. Eight php-fpm workers each use about 10% CPU, all in the running state, and the CPU is at 100%." width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Laravel Rust never got there in my runs. It had zero failed requests in all seven of its ramps. Past its limit, its latency grew instead. On the 1 GB box its p95 over the whole ramp was about 3.5 seconds, but not one request hit k6's 5-second timeout.&lt;/p&gt;

&lt;p&gt;So know where your PHP app's ceiling is, and keep real traffic well below it. In these runs there was no slow band between fine and down.&lt;/p&gt;

&lt;h2&gt;
  
  
  The OOM killer picked MySQL, three times
&lt;/h2&gt;

&lt;p&gt;On the 1 vCPU, 961 MiB VPS, the kernel ran out of memory three times. That was once in the first PHP-FPM round, and again in the second and third Octane rounds. Each time it killed MySQL, the process with the most memory. It never happened during a Rust run. This is the third one, from the kernel log:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dec 02 13:26:09 bench-vps kernel: nginx invoked oom-killer: gfp_mask=0x140cca(GFP_HIGHUSER_MOVABLE|__GFP_COMP), order=0, oom_score_adj=0
Dec 02 13:26:09 bench-vps kernel: Out of memory: Killed process 6561 (mysqld) total-vm:1405416kB, anon-rss:480632kB, file-rss:2816kB, shmem-rss:0kB, UID:108 pgtables:1368kB oom_score_adj:0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the two Octane rounds, the app logged &lt;code&gt;Connection refused&lt;/code&gt; for about 5 seconds, until MySQL was back. In a real app, every page that touches the database fails for those seconds, because of traffic the app couldn't serve anyway.&lt;/p&gt;

&lt;p&gt;If you run MySQL and PHP on a 1 GB box, decide which process the kernel should take before it decides for you. systemd's &lt;code&gt;OOMScoreAdjust=&lt;/code&gt; is the setting for that, although I didn't test it here.&lt;/p&gt;

&lt;h2&gt;
  
  
  A cheap shared vCPU is not a dedicated vCPU
&lt;/h2&gt;

&lt;p&gt;The steady 50 requests per second also ran on the dedicated EPYC vCPU and on the €7 VPS with its two shared Skylake vCPUs. Same apps, same load, very different CPU bills:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-rust-vs-php-benchmark-hetzner" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Rust needed 4.9 times as much CPU on the shared vCPU, Octane 3.9 times and PHP-FPM 2.8 times. Both PHP setups used more than one full vCPU of the VPS for just 50 requests per second. So "1 vCPU" isn't a unit you can compare between a €7 plan and a dedicated one. Benchmark on the plan you'll actually pay for.&lt;/p&gt;

&lt;p&gt;Memory at 50 requests per second on the dedicated box was small for all three. Laravel Rust used 6.7 MiB of its own memory, Octane 88.9 MiB and PHP-FPM 27.9 MiB. With the file cache the kernel charges to the app (binary, PHP files, OPcache) it was 114, 220 and 162 MiB. Laravel reported 16M and 134M on Cloud, measured with Cloud's own metrics, so compare the ratios rather than the values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requests per euro
&lt;/h2&gt;

&lt;p&gt;Hetzner charges €6.70 a month for the cx23 plus €0.61 for its IPv4 address, VAT included. A dedicated vCPU is a quarter of a ccx23, which is €22.26. Taking each best window as a rate held for a 30-day month:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Requests per € per month&lt;/th&gt;
&lt;th&gt;Laravel Rust&lt;/th&gt;
&lt;th&gt;Octane&lt;/th&gt;
&lt;th&gt;PHP-FPM&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;€7 VPS, 2 shared vCPU&lt;/td&gt;
&lt;td&gt;359 M&lt;/td&gt;
&lt;td&gt;32 M&lt;/td&gt;
&lt;td&gt;22 M&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1 dedicated vCPU&lt;/td&gt;
&lt;td&gt;232 M (at least)&lt;/td&gt;
&lt;td&gt;19 M&lt;/td&gt;
&lt;td&gt;11 M&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The €7 VPS wins for every runtime. It served half to two thirds of what the dedicated vCPU did, for a third of the price, and that price includes the database server. I went through the wider &lt;a href="https://hafiz.dev/blog/laravel-cloud-vs-forge-vs-vps-cost-comparison" rel="noopener noreferrer"&gt;Cloud vs Forge vs VPS cost question&lt;/a&gt; in an earlier post.&lt;/p&gt;

&lt;p&gt;In absolute terms, Octane's 90 requests per second on the €7 VPS is 7.8 million requests a day. Laravel Rust's 1,013 is 87.5 million.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this means for your app
&lt;/h2&gt;

&lt;p&gt;The benchmark API is small. It serves a paginated feed and single chirps from MySQL, over 10 authors and 200 chirps. With work that light, the framework is most of each request, and that's where a compiled runtime pulls furthest ahead. In an app whose requests spend most of their time in the database, the gap should shrink, because a slow query costs the same whichever runtime sends it. If your pages are slow, &lt;a href="https://hafiz.dev/blog/database-indexing-in-laravel-boost-mysql-performance-with-smart-indexes" rel="noopener noreferrer"&gt;the right index&lt;/a&gt; or &lt;a href="https://hafiz.dev/blog/laravel-query-optimization-from-3-seconds-to-30ms" rel="noopener noreferrer"&gt;a rewritten query&lt;/a&gt; will usually buy you more than a new runtime.&lt;/p&gt;

&lt;p&gt;If you're on PHP-FPM, Octane is the cheaper step. It served 1.4 to 1.8 times as much on the same box, with no rewrite. It does keep your app in memory between requests, which brings its own bugs, and I compared &lt;a href="https://hafiz.dev/blog/laravel-octane-2026-frankenphp-vs-swoole-vs-roadrunner" rel="noopener noreferrer"&gt;FrankenPHP, Swoole and RoadRunner for Octane&lt;/a&gt; separately.&lt;/p&gt;

&lt;p&gt;Laravel Rust is at version 0.1.0. A release build took 181.8 seconds on 4 dedicated vCPUs and 657.4 seconds on the €7 VPS, against 3.6 seconds for &lt;code&gt;composer install&lt;/code&gt;. Laravel's own median build on Cloud was 3 minutes 1 second. The binary is 32.8 MB.&lt;/p&gt;

&lt;p&gt;I wouldn't rewrite a working Laravel app for this. I'd try it first on a new service with one hot endpoint, or on something that has to live on a tiny box. My next test ports the read path of a real Laravel app to Laravel Rust, to see how much of the 12× survives real queries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits of this test
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Rust's ceiling on the dedicated vCPU is unmeasured.&lt;/strong&gt; The k6 server was close to 100% CPU near the 2,000 cap, so part of the 44 ms p95 may be the load generator queueing. The requests per euro for that row are a lower bound.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Plain HTTP on a private network.&lt;/strong&gt; Laravel's requests crossed TLS and Cloud's edge, so compare my latencies with each other, not with theirs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latency near the limit swings between rounds.&lt;/strong&gt; Octane on the €7 VPS had a best-window p95 between 398 ms and 2.9 seconds across three rounds, while its throughput only moved between 88 and 95. That's why I lead with throughput.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two memory figures.&lt;/strong&gt; "Its own memory" is the app's anonymous memory. The larger figure adds file cache.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;htop ran during the third round on 1 vCPU&lt;/strong&gt;, using about 1% CPU (2% with its tmux session). Rust's third round matched the other two (564, 562 and 562).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;One region, one day, one small API.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reproduce it
&lt;/h2&gt;

&lt;p&gt;The apps and the k6 script are in &lt;a href="https://github.com/laravel/laravel-framework-benchmarking-2026" rel="noopener noreferrer"&gt;Laravel's benchmark repo&lt;/a&gt; at commit &lt;code&gt;c506879&lt;/code&gt;, and its README covers every setting I copied. My runs kept the official &lt;code&gt;benchmark.js&lt;/code&gt; byte for byte. The extra profiles (the 500 cap and a fixed-rate hold) live in a separate script. That script, my server setup and the results of every run are in &lt;a href="https://github.com/hzeeshan/laravel-rust-bench" rel="noopener noreferrer"&gt;hzeeshan/laravel-rust-bench&lt;/a&gt;. Credit to Sam Rose for publishing everything needed to check his work. Without that, this post would be a guess.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Should I rewrite my Laravel app in Laravel Rust?
&lt;/h3&gt;

&lt;p&gt;Probably not yet. It's at version 0.1.0, a release build takes minutes instead of seconds, and the gap I measured comes from a tiny API where the framework is most of the work. If your app is slow because of its queries, a new runtime won't fix that. Try it on a new service with one hot endpoint first.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why are these numbers different from Laravel's?
&lt;/h3&gt;

&lt;p&gt;The hardware is different, no TLS or edge sat between k6 and the app, and the region is different. Octane did better on my dedicated vCPU (167 against 97), and Rust hit the 2,000 cap, so the ratio came out at 11 to 13× instead of 18×. The direction and the order of magnitude match.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is Octane worth it on a cheap VPS?
&lt;/h3&gt;

&lt;p&gt;On the €7 VPS it served 90 requests per second against 62 for PHP-FPM, and 44.5 against 31 on the 1 GB boot. That's about 1.4 to 1.5 times as much, with no code changes. But on 1 GB, MySQL also got killed twice during Octane runs. Give it memory headroom.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>laravelrust</category>
      <category>performance</category>
      <category>php</category>
    </item>
    <item>
      <title>Pun vs Pint, Larastan and Composer on a Real Laravel App: What Got Faster, What Broke</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Mon, 30 Nov 2026 05:15:09 +0000</pubDate>
      <link>https://dev.to/hafiz619/pun-vs-pint-larastan-and-composer-on-a-real-laravel-app-what-got-faster-what-broke-1pn2</link>
      <guid>https://dev.to/hafiz619/pun-vs-pint-larastan-and-composer-on-a-real-laravel-app-what-got-faster-what-broke-1pn2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/pun-vs-pint-larastan-composer-real-laravel-app" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Pun, built by Pushpak Chhajed, wants to replace six tools with one binary. It formats like Pint and PHP-CS-Fixer, analyses like PHPStan and Larastan, refactors like Rector and installs packages like Composer, all from one Rust executable and one &lt;code&gt;pun.toml&lt;/code&gt;. Nuno Maduro &lt;a href="https://x.com/enunomaduro/status/2125229114047275183" rel="noopener noreferrer"&gt;called it&lt;/a&gt; "bun, but for php" when it went into public beta in late November.&lt;/p&gt;

&lt;p&gt;Most results I'd seen came from small sample projects. So I ran Pun 0.4.4 on a copy of Prompt Optimizer, a production Laravel 13 app with about 440 PHP files of its own and 944 tests, next to the tools it wants to replace. I timed everything, diffed the output and ran the test suite on both &lt;code&gt;vendor/&lt;/code&gt; folders.&lt;/p&gt;

&lt;p&gt;Formatting is a clear win. Installs are faster once the cache is warm. The analyser is the part I wouldn't swap yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I tested
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The app.&lt;/strong&gt; A copy of Prompt Optimizer at Laravel 13.38, with about 440 PHP files and 49,000 lines outside &lt;code&gt;vendor/&lt;/code&gt;, and 179 packages inside it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The machine.&lt;/strong&gt; Apple M1 Pro, 8 cores, 16 GB of memory, PHP 8.3.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The incumbents.&lt;/strong&gt; Pint 1.32.1, the version locked in the app, with the default Laravel preset (the app has no &lt;code&gt;pint.json&lt;/code&gt;), Larastan 3.15.0 on PHPStan 2.3.7 at level 5 on &lt;code&gt;app/&lt;/code&gt;, and Composer 2.11.3. The app ships with Pint only, so I added Larastan for this comparison.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The challenger.&lt;/strong&gt; Pun 0.4.4, installed through Composer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I ran each command five or six times and quote the median of the runs after the first. Every number and every output block below is real.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require --dev shipfastlabs/pun
vendor/bin/pun --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pun: downloading https://github.com/shipfastlabs/pun/releases/download/v0.4.4/punphp-aarch64-apple-darwin.tar.gz
pun: verified the GitHub build attestation
pun 0.4.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Composer package is a small PHP shim. On first run it downloads the binary for your platform into &lt;code&gt;vendor/bin&lt;/code&gt;, checks its SHA-256 checksum and, with a signed-in &lt;code&gt;gh&lt;/code&gt;, the GitHub build attestation. That binary is 83 MB. And because it lives in &lt;code&gt;vendor/bin&lt;/code&gt;, every fresh &lt;code&gt;vendor/&lt;/code&gt; downloads it again. I watched it happen each time I rebuilt &lt;code&gt;vendor/&lt;/code&gt; for the install tests. In CI, cache it or use the standalone installer, which puts the binary in &lt;code&gt;~/.pun/bin&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  pun migrate wrote the config in a tenth of a second
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/pun migrate --dry-run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pun migrate: dry-run, starter pun.toml to write (preset laravel, 115 format rules, 15 lint rules), ignore comments to rewrite in 0 files (0.09s)
phpstan.neon migrate
phpstan.neon unsupported format/functions/backtick-to-shell-exec: a PHPStan check that is this format rule in Pun; turn it on in [format.rules]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The real run took 0.06 seconds. It read &lt;code&gt;composer.lock&lt;/code&gt;, switched on the Laravel, PHPUnit, Carbon and Mockery extensions, and turned PHPStan level 5 into a preset:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[extensions]&lt;/span&gt;
&lt;span class="na"&gt;laravel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"on"&lt;/span&gt;
&lt;span class="na"&gt;phpunit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"on"&lt;/span&gt;
&lt;span class="na"&gt;carbon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"on"&lt;/span&gt;
&lt;span class="na"&gt;mockery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"on"&lt;/span&gt;

&lt;span class="k"&gt;[format]&lt;/span&gt;
&lt;span class="na"&gt;preset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"laravel"&lt;/span&gt;

&lt;span class="k"&gt;[analyse]&lt;/span&gt;
&lt;span class="na"&gt;preset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"phpstan/level_5"&lt;/span&gt;
&lt;span class="na"&gt;paths&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"app"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It also wrote 15 lint rules from Pint's Laravel preset, and moved 9 PHPStan level 5 checks, such as duplicate array keys, into lint for &lt;code&gt;app/&lt;/code&gt;. One check didn't map, and the output tells you which one.&lt;/p&gt;

&lt;p&gt;One warning before you run it on your own project. &lt;code&gt;pun migrate&lt;/code&gt; rewrites &lt;code&gt;@phpstan-ignore&lt;/code&gt; and &lt;code&gt;@php-cs-fixer-ignore&lt;/code&gt; comments in your PHP files to &lt;code&gt;@pun-ignore&lt;/code&gt;. My app had none. Yours might, so start from a clean working tree.&lt;/p&gt;

&lt;h2&gt;
  
  
  Formatting is 35 times faster, with the same bytes
&lt;/h2&gt;

&lt;p&gt;Check mode on the whole project, no files changed:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Median&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;vendor/bin/pint --test&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2.82 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;vendor/bin/pint --test --parallel&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1.30 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;vendor/bin/pun format --test&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0.08 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Pint's &lt;code&gt;--parallel&lt;/code&gt; flag is still marked experimental, and Pun beats it 16 to 1. Against plain Pint it's 35 to 1. The 0.08 seconds includes booting the PHP shim. Calling the binary directly took 0.03 seconds.&lt;/p&gt;

&lt;p&gt;Speed means nothing if the output differs, though. The codebase had drifted from Pint's current rules, and both tools flagged the same 63 files. So I let each one fix them on its own branch and diffed the branches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout -b pint-fix &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; vendor/bin/pint &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit -qam &lt;span class="s2"&gt;"pint"&lt;/span&gt;
git checkout main &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git checkout -b pun-fix &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; vendor/bin/pun format &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit -qam &lt;span class="s2"&gt;"pun"&lt;/span&gt;
git diff --stat pint-fix pun-fix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The diff was empty. Both branches changed 63 files with 215 insertions and 125 deletions, and &lt;code&gt;pint --test&lt;/code&gt; passes on Pun's output. Byte for byte, as the README promises.&lt;/p&gt;

&lt;p&gt;One person on a team can move to Pun without the formatter fighting everyone else in every pull request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Analysis matched 131 of 136 findings after one config change
&lt;/h2&gt;

&lt;p&gt;With default settings, Larastan found 223 errors in &lt;code&gt;app/&lt;/code&gt;, and Pun, on the config &lt;code&gt;pun migrate&lt;/code&gt; wrote, found 221. I matched them on file, line and error identifier. 209 were identical, 14 came from Larastan only and 12 from Pun only. Then I looked at what the differences had in common.&lt;/p&gt;

&lt;h3&gt;
  
  
  Both analysers misread casts() by default
&lt;/h3&gt;

&lt;p&gt;Seven of Pun's 12 extra findings had the same shape. Here's one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;casts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'tags'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'array'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="c1"&gt;// ...&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getTagsStringAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;is_array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;implode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;', '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/Models/Post.php:180 analyse/dead-code/impossible-type-check Call to function is_array() with string|null will always evaluate to false.
app/Models/Post.php:180 analyse/types/argument Parameter #2 $array of function implode expects array, string|null given.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;tags&lt;/code&gt; column is &lt;code&gt;$table-&amp;gt;json('tags')-&amp;gt;nullable()&lt;/code&gt;. Both tools typed it from the migration as &lt;code&gt;string|null&lt;/code&gt; and ignored the &lt;code&gt;array&lt;/code&gt; cast. Larastan reports the &lt;code&gt;is_array()&lt;/code&gt; line too. It stops there because it treats the &lt;code&gt;implode()&lt;/code&gt; branch as unreachable, while Pun reports both lines.&lt;/p&gt;

&lt;p&gt;Larastan builds the model without running its constructor, so &lt;code&gt;getCasts()&lt;/code&gt; never sees &lt;code&gt;casts()&lt;/code&gt;. By default it only reads the declared return type of &lt;code&gt;casts()&lt;/code&gt;, which is plain &lt;code&gt;array&lt;/code&gt;. The &lt;a href="https://github.com/larastan/larastan/blob/3.x/docs/custom-config-parameters.md" rel="noopener noreferrer"&gt;&lt;code&gt;parseModelCastsMethod&lt;/code&gt;&lt;/a&gt; option parses the method body instead, and it's off by default because parsing is slower. Pun copies that default. That's a trap for any app written since Laravel 11, because the &lt;a href="https://laravel.com/docs/13.x/eloquent-mutators#attribute-casting" rel="noopener noreferrer"&gt;Laravel docs&lt;/a&gt; have shown casts as a method since then.&lt;/p&gt;

&lt;p&gt;So I switched it on in &lt;code&gt;phpstan.neon&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;includes:
    - vendor/larastan/larastan/extension.neon

parameters:
    paths:
        - app/
    level: 5
    parseModelCastsMethod: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I ran &lt;code&gt;pun migrate&lt;/code&gt; again. It carried the setting over as an option on two Laravel rules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[analyse.rules]&lt;/span&gt;
&lt;span class="s2"&gt;"laravel/redundant-collection-call"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;casts&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="s2"&gt;"laravel/undefined-model-append"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;casts&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Larastan dropped from 223 errors to 136, and Pun from 221 to 133. Of those, 131 matched. One default had produced 87 of Larastan's 223 errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's left after that
&lt;/h3&gt;

&lt;p&gt;Five findings came from Larastan only:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a &lt;code&gt;?-&amp;gt;&lt;/code&gt; on &lt;code&gt;auth()-&amp;gt;user()&lt;/code&gt; after an earlier check already proved the user exists&lt;/li&gt;
&lt;li&gt;a property read through a relation typed as the base &lt;code&gt;Model&lt;/code&gt; class&lt;/li&gt;
&lt;li&gt;two &lt;code&gt;str_contains()&lt;/code&gt; checks on an error message that Larastan proved can never match&lt;/li&gt;
&lt;li&gt;an array passed to the Stripe SDK that doesn't match the SDK's documented array shape&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two came from Pun only. One is a read of &lt;code&gt;$post-&amp;gt;tags&lt;/code&gt; inside an &lt;code&gt;! empty()&lt;/code&gt; check, which narrows the type for Larastan but not for Pun. The other is a &lt;code&gt;match&lt;/code&gt; on a string the code validates earlier with &lt;code&gt;in_array()&lt;/code&gt;, which Pun flags as not exhaustive and Larastan doesn't.&lt;/p&gt;

&lt;p&gt;None of them is exotic. The &lt;a href="https://punphp.com/docs/commands/analyse" rel="noopener noreferrer"&gt;analyse docs&lt;/a&gt; are upfront that some PHPStan and Larastan checks are still marked Planned.&lt;/p&gt;

&lt;h3&gt;
  
  
  Speed depends on the result cache
&lt;/h3&gt;

&lt;p&gt;With casts read in both tools:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Median&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Larastan, result cache cleared&lt;/td&gt;
&lt;td&gt;3.32 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Larastan, warm result cache&lt;/td&gt;
&lt;td&gt;1.06 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;pun analyse&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1.70 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;pun check&lt;/code&gt; (format, lint and analyse)&lt;/td&gt;
&lt;td&gt;1.69 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Parsing &lt;code&gt;casts()&lt;/code&gt; didn't make Larastan measurably slower. The cold run took 3.32 seconds with it and 3.26 without.&lt;/p&gt;

&lt;p&gt;A warm Larastan was faster than Pun, though. PHPStan's &lt;a href="https://phpstan.org/user-guide/result-cache" rel="noopener noreferrer"&gt;result cache&lt;/a&gt; only analyses the files that changed since the last run, plus the files that depend on them. Pun took between 1.69 and 1.76 seconds on every run after the first, with no cache effect I could see. Its docs say it reads &lt;code&gt;vendor/&lt;/code&gt; for classes and functions, and this &lt;code&gt;vendor/&lt;/code&gt; holds almost 20,000 PHP files.&lt;/p&gt;

&lt;p&gt;So the fair comparison depends on where you run it. On a &lt;a href="https://hafiz.dev/blog/laravel-cicd-github-actions-complete-guide" rel="noopener noreferrer"&gt;CI runner&lt;/a&gt; that doesn't restore the PHPStan cache between runs, Pun is almost twice as fast. On your laptop after the first run, Larastan wins. (I covered what each Larastan level catches in &lt;a href="https://hafiz.dev/blog/larastan-every-level-agent-written-laravel-code" rel="noopener noreferrer"&gt;running Larastan at every level on agent-written code&lt;/a&gt;.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Lint found one real bug
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;pun lint&lt;/code&gt; with the migrated rules took about a second and reported 10 problems in 8 files, all with safe fixes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;6 redundant nullsafe operators (&lt;code&gt;?-&amp;gt;&lt;/code&gt; on values that can't be null)&lt;/li&gt;
&lt;li&gt;3 private constants that nothing reads&lt;/li&gt;
&lt;li&gt;1 duplicate array key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The duplicate key is a real bug. An array of prompts had the key &lt;code&gt;'literary critic'&lt;/code&gt; twice, so the first value was silently lost. Larastan reports it too, but in a list of 136 errors it's easy to scroll past. Pint never looks at this kind of thing, because it only formats.&lt;/p&gt;

&lt;p&gt;Before you run &lt;code&gt;pun lint --fix&lt;/code&gt; across a whole codebase, read the open issues. One of them, &lt;a href="https://github.com/shipfastlabs/pun/issues/32" rel="noopener noreferrer"&gt;#32&lt;/a&gt;, reports a rule that removes an integer cast the code needs and causes a &lt;code&gt;TypeError&lt;/code&gt;. My migrated config didn't trip it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installs are faster warm and a tie cold
&lt;/h2&gt;

&lt;p&gt;I used Composer 2.11.3, the release line with the &lt;a href="https://hafiz.dev/blog/composer-2-11-cooldown-laravel" rel="noopener noreferrer"&gt;cooldown I tested in November&lt;/a&gt;. For the first and last rows I deleted &lt;code&gt;vendor/&lt;/code&gt; before each run:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Composer 2.11.3&lt;/th&gt;
&lt;th&gt;&lt;code&gt;pun install&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Warm cache&lt;/td&gt;
&lt;td&gt;6.24 s&lt;/td&gt;
&lt;td&gt;4.11 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nothing changed&lt;/td&gt;
&lt;td&gt;3.09 s&lt;/td&gt;
&lt;td&gt;0.62 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Empty cache&lt;/td&gt;
&lt;td&gt;12.7 to 14.4 s&lt;/td&gt;
&lt;td&gt;10.8 to 15.2 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;An empty cache means downloading every package, so the network decides. The ranges overlap. I call it a tie.&lt;/p&gt;

&lt;p&gt;Pun prints where its time goes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; + packages: 179 installed (179 from the cache)
 + autoloader: 15024 classes
Installed in 3.9s (Pun 3.3s, Composer scripts and plugins 0.6s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pun still runs your Composer scripts, and they still need PHP. Here that's &lt;code&gt;package:discover&lt;/code&gt; and &lt;code&gt;filament:upgrade&lt;/code&gt;, which take 0.6 seconds, and that's the whole of the no-op install. Composer's no-op dumps the autoloader again and runs the same scripts, and takes 3.09 seconds.&lt;/p&gt;

&lt;p&gt;Then I checked the result. I ran the full PHPUnit suite once on Composer's &lt;code&gt;vendor/&lt;/code&gt; and once on Pun's. All 944 tests had the same outcome, test by test. (The copy had no built front-end assets and no production API keys, so the same 110 tests failed on both.)&lt;/p&gt;

&lt;p&gt;One trade-off from the &lt;a href="https://punphp.com/docs/commands/install" rel="noopener noreferrer"&gt;install docs&lt;/a&gt;. Pun hardlinks packages from a shared store by default, so editing a file in &lt;code&gt;vendor/&lt;/code&gt; edits it in every project that shares that package. If you patch vendor files while debugging, set &lt;code&gt;--link-mode=copy&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'm switching
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Formatting moves to Pun now.&lt;/strong&gt; It's byte-identical to Pint, and the pre-commit hook stops being something I wait for. &lt;code&gt;pun check --dirty&lt;/code&gt; took 1.2 seconds on one changed file, against 1.8 seconds for &lt;code&gt;pint --dirty&lt;/code&gt; plus Larastan on that file. (If the hook also runs tests, &lt;a href="https://hafiz.dev/blog/pest-5-tia-run-only-tests-your-change-touched" rel="noopener noreferrer"&gt;Pest's test impact analysis&lt;/a&gt; keeps that part short.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Larastan stays in CI.&lt;/strong&gt; Five misses and two extras are close, but the tool that blocks a merge has to catch everything the old one did. I'll run the comparison again on the next Pun release.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;pun install&lt;/code&gt; is for local work.&lt;/strong&gt; The 0.6-second no-op is the install I hit dozens of times a day. CI and deploys stay on Composer while Pun is in beta, since a cold install isn't faster anyway.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And pin the version. The installation docs still show 0.2.7 in their example, and I installed 0.4.4 a few days after launch. This thing moves fast.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Can Pun replace Pint without changing my code style?
&lt;/h3&gt;

&lt;p&gt;On this app, yes. Both tools changed the same 63 files in exactly the same way, and Pint passed on Pun's output. There are limits. Pint's &lt;code&gt;symfony&lt;/code&gt; preset isn't supported, and custom rules or closures in your Pint config are skipped with a warning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does Pun need PHP installed?
&lt;/h3&gt;

&lt;p&gt;Not for &lt;code&gt;format&lt;/code&gt;, &lt;code&gt;lint&lt;/code&gt; and &lt;code&gt;analyse&lt;/code&gt;. &lt;code&gt;pun install&lt;/code&gt; still runs your Composer scripts, which need PHP, and migrating a &lt;code&gt;rector.php&lt;/code&gt; or &lt;code&gt;.php-cs-fixer.php&lt;/code&gt; file needs PHP and that tool.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is pun analyse a drop-in replacement for Larastan?
&lt;/h3&gt;

&lt;p&gt;Not yet. With &lt;code&gt;parseModelCastsMethod&lt;/code&gt; on in both tools, it matched 131 of Larastan's 136 findings on a real Laravel 13 app at level 5, missed 5 and added 2. Without that option both tools misread &lt;code&gt;casts()&lt;/code&gt;, so compare them with it on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is pun install faster than composer install?
&lt;/h3&gt;

&lt;p&gt;With a warm cache it took 4.1 seconds against 6.2. When nothing changed it took 0.6 seconds against 3.1. With an empty cache both are limited by the network and took about the same time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does Pun add 83 MB to vendor/?
&lt;/h3&gt;

&lt;p&gt;The Composer package is only a PHP shim. On first run the shim downloads the native binary for your platform into &lt;code&gt;vendor/bin&lt;/code&gt;, and that binary is 83 MB. Every fresh &lt;code&gt;vendor/&lt;/code&gt; repeats the download unless you cache it or install Pun globally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turn on parseModelCastsMethod first
&lt;/h2&gt;

&lt;p&gt;If your models declare casts in a &lt;code&gt;casts()&lt;/code&gt; method, Larastan and Pun both ignore them until you set &lt;code&gt;parseModelCastsMethod: true&lt;/code&gt; in &lt;code&gt;phpstan.neon&lt;/code&gt;, which &lt;code&gt;pun migrate&lt;/code&gt; carries into &lt;code&gt;pun.toml&lt;/code&gt;. On this app that one line removed 87 of Larastan's 223 errors, and it didn't make the cold run measurably slower. Set it before you compare analysers, and before you trust either one.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>pun</category>
      <category>larastan</category>
    </item>
    <item>
      <title>A Bot Signed Politicians Up to My Laravel Newsletter. 9 Got Through, Then 93 Didn't</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Thu, 26 Nov 2026 05:15:08 +0000</pubDate>
      <link>https://dev.to/hafiz619/a-bot-signed-politicians-up-to-my-laravel-newsletter-9-got-through-then-93-didnt-3k2l</link>
      <guid>https://dev.to/hafiz619/a-bot-signed-politicians-up-to-my-laravel-newsletter-9-got-through-then-93-didnt-3k2l</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/laravel-newsletter-subscription-bombing-turnstile" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;On the morning of 19 November my phone showed eight new newsletter subscribers in under an hour and a half. Six of the addresses ended in &lt;code&gt;@bundestag.de&lt;/code&gt;, the German parliament. One was at the European Commission. None of those people wanted my Laravel tips.&lt;/p&gt;

&lt;p&gt;My Laravel form had a honeypot, a rate limit and email validation. So how did eight bot signups end up as active subscribers in my newsletter provider?&lt;/p&gt;

&lt;p&gt;Two layers I added that same morning have stopped every attempt since. By the morning of 20 November that was 93 of them, and none had got through.&lt;/p&gt;

&lt;h2&gt;
  
  
  What subscription bombing is
&lt;/h2&gt;

&lt;p&gt;The attack has a name. In &lt;a href="https://bytemash.net/posts/subscription-bombing-your-signup-form-is-a-weapon/" rel="noopener noreferrer"&gt;subscription bombing&lt;/a&gt;, a bot types a victim's email address into hundreds or thousands of signup forms across the web. Each site sends a welcome or confirmation email, and the victim's inbox floods. The flood buries real emails the attacker doesn't want seen, like a password reset or a bank alert.&lt;/p&gt;

&lt;p&gt;So my site wasn't the target. It was one of the tools. That also explains why it looked so polite. One signup per victim per site is all the attack needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I knew it was a bot
&lt;/h2&gt;

&lt;p&gt;The addresses alone were suspicious. The access log settled it. Here are the POSTs to the form that morning (UTC, Cloudflare edge IP, status, response size, user agent):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[19/Nov/2026:05:16:36 172.71.144.92  200 119  Mozilla/5.0 (X11; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0
[19/Nov/2026:05:22:22 172.70.250.188  200 119  Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Mobile/15E148 Safari/604.1
[19/Nov/2026:05:36:21 172.71.148.170  200 119  Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15
[19/Nov/2026:05:47:22 172.71.164.89  200 119  Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0
[19/Nov/2026:06:16:35 172.70.250.189  200 119  Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Mobile/15E148 Safari/604.1
[19/Nov/2026:06:30:31 162.158.94.239  200 119  Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Four different "browsers", all versions from spring 2024, rotated on every request. The real client IPs (which Laravel sees through Cloudflare's forwarded headers) were two addresses in Amsterdam datacenter ranges that VPN services use. A real visitor doesn't switch from an iPhone to Windows Firefox between signups.&lt;/p&gt;

&lt;p&gt;The first address it tried wasn't a politician at all. Two days earlier, from the same IP, the bot had signed up an address on &lt;code&gt;jud3.dev&lt;/code&gt;. That domain's MX records point at Cloudflare Email Routing, which is a common way to run a catch-all inbox. Most likely that was the bot checking that my form takes any address without a CAPTCHA. It did, so my form went on its list.&lt;/p&gt;

&lt;h2&gt;
  
  
  The three defenses on the form
&lt;/h2&gt;

&lt;p&gt;Here is what the form had in front of it on 19 November. A hidden honeypot field called &lt;code&gt;website&lt;/code&gt;, which real visitors never see. The route had &lt;code&gt;throttle:5,1&lt;/code&gt;, so five attempts per minute per IP. And Laravel's &lt;code&gt;email&lt;/code&gt; validation rule on the address.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-newsletter-subscription-bombing-turnstile" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ cat storage/logs/laravel-2026-11-1&lt;span class="o"&gt;[&lt;/span&gt;7-9&lt;span class="o"&gt;]&lt;/span&gt;.log storage/logs/laravel-2026-11-20.log &lt;span class="o"&gt;|&lt;/span&gt; grep -c &lt;span class="s2"&gt;"honeypot triggered"&lt;/span&gt;
0
$ grep -h &lt;span class="s2"&gt;"sent to ConvertKit"&lt;/span&gt; storage/logs/laravel-2026-11-19.log &lt;span class="o"&gt;|&lt;/span&gt; grep -oE &lt;span class="s1"&gt;'"email":"[^"]*"|"state":"[^"]*"'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; paste - - - &lt;span class="o"&gt;|&lt;/span&gt; head -8
&lt;span class="s2"&gt;"email"&lt;/span&gt;:&lt;span class="s2"&gt;"…@mj.jud3.dev"&lt;/span&gt;   &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;    &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;
&lt;span class="s2"&gt;"email"&lt;/span&gt;:&lt;span class="s2"&gt;"…@bundestag.de"&lt;/span&gt;  &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;    &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;
&lt;span class="s2"&gt;"email"&lt;/span&gt;:&lt;span class="s2"&gt;"…@bundestag.de"&lt;/span&gt;  &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;    &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;
&lt;span class="s2"&gt;"email"&lt;/span&gt;:&lt;span class="s2"&gt;"…@bundestag.de"&lt;/span&gt;  &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;    &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;
&lt;span class="s2"&gt;"email"&lt;/span&gt;:&lt;span class="s2"&gt;"…@bundestag.de"&lt;/span&gt;  &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;    &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;
&lt;span class="s2"&gt;"email"&lt;/span&gt;:&lt;span class="s2"&gt;"…@ec.europa.eu"&lt;/span&gt;  &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;    &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;
&lt;span class="s2"&gt;"email"&lt;/span&gt;:&lt;span class="s2"&gt;"…@bundestag.de"&lt;/span&gt;  &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;    &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;
&lt;span class="s2"&gt;"email"&lt;/span&gt;:&lt;span class="s2"&gt;"…@bundestag.de"&lt;/span&gt;  &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;    &lt;span class="s2"&gt;"state"&lt;/span&gt;:&lt;span class="s2"&gt;"active"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;None. (I've cut the local part of each address.) Every signup reached Kit, and Kit made every address an &lt;code&gt;active&lt;/code&gt; subscriber, because my form was single opt-in. Nine got through in total, the eight above plus the test signup two days earlier. The last two above arrived while I was writing the fix. Each defense missed for a plain reason. The honeypot only catches bots that fill in every field they find, and this one sent the email and left &lt;code&gt;website&lt;/code&gt; empty. The throttle counts requests per IP per minute, and the bot sent one request every 10 to 15 minutes. (Laravel has sharper tools for other limits, like &lt;a href="https://hafiz.dev/blog/laravel-cache-funnel-concurrency-limiting" rel="noopener noreferrer"&gt;&lt;code&gt;Cache::funnel&lt;/code&gt; for concurrency&lt;/a&gt;, but a per-IP limit can't see a bot that's slow on purpose and keeps changing IPs.) And the addresses were valid, because they belong to real people. That's the whole point of the attack.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cleaning up first
&lt;/h2&gt;

&lt;p&gt;The first job was the newsletter list itself, before the next post's broadcast went out. The form already talked to Kit's v3 API, so the cleanup used the same credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Http&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Http&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'services.convertkit.base_url'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'/unsubscribe'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'api_secret'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'services.convertkit.api_key'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'subscriber.state'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// "cancelled"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every address came back &lt;code&gt;cancelled&lt;/code&gt;, and I deleted the local rows only after that. Kit's &lt;a href="https://developers.kit.com/api-reference/v3/subscribers" rel="noopener noreferrer"&gt;v3 API reference&lt;/a&gt; marks v3 as deprecated in favour of v4, so a new integration should use v4.&lt;/p&gt;

&lt;p&gt;My own code had made one more mess. When Kit accepted a signup, the controller set the local row's &lt;code&gt;status&lt;/code&gt; to &lt;code&gt;confirmed&lt;/code&gt;. So my admin panel listed an address at the European Commission as a confirmed subscriber. In my code, "confirmed" only ever meant "Kit didn't return an error".&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer one: a block list that lies
&lt;/h2&gt;

&lt;p&gt;The quickest fix was a block list in the controller. The form already had a list for one disposable-mail domain. I added the domains the bot was using, and made subdomains match, because the test address was on &lt;code&gt;mj.jud3.dev&lt;/code&gt;, not &lt;code&gt;jud3.dev&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;BLOCKED_DOMAINS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'immenseignite.info'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'jud3.dev'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'bundestag.de'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'ec.europa.eu'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'europarl.europa.eu'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isBlockedDomain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$domain&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;BLOCKED_DOMAINS&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$blocked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$domain&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$blocked&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nf"&gt;str_ends_with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$domain&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'.'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$blocked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A blocked request gets the same JSON success message as a real signup, but nothing is saved and nothing goes to Kit. A bot that sees an error changes its input. A bot that sees success moves on to the next victim and keeps sending me addresses I already block.&lt;/p&gt;

&lt;p&gt;It worked. By the morning of 20 November the block list had quietly accepted and thrown away 80 attempts, almost all of them &lt;code&gt;@bundestag.de&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I added the two client IPs as well, and they turned out to be the weakest part. Over the next day the bot used eight different IPs in three ranges. IP blocking against a VPN user is a guess about where they'll be tomorrow.&lt;/p&gt;

&lt;p&gt;The domain list has the same problem in slower motion. It only knows the domains I've already seen. So the next morning, when the bot moved on to party and parliamentary-group domains that weren't on the list, it needed something that doesn't depend on knowing the attacker in advance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer two: Cloudflare Turnstile, checked on the server
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developers.cloudflare.com/turnstile/" rel="noopener noreferrer"&gt;Turnstile&lt;/a&gt; is Cloudflare's CAPTCHA replacement. It runs checks in the visitor's browser and hands the page a token, and most real visitors never see anything. It's free, and the site doesn't have to be proxied through Cloudflare to use it. Mine is, as part of &lt;a href="https://hafiz.dev/blog/how-i-hardened-my-vps-ssh-cloudflare-tailscale" rel="noopener noreferrer"&gt;how I hardened this VPS&lt;/a&gt;, but that's not a requirement.&lt;/p&gt;

&lt;p&gt;The browser part proves nothing on its own. This bot never ran my page's JavaScript. It posted straight to &lt;code&gt;/newsletter/subscribe&lt;/code&gt;. Cloudflare's docs say it directly: "The client-side widget alone does not protect your forms." The lock is the server calling &lt;code&gt;siteverify&lt;/code&gt; with the token and the secret key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;passesTurnstile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$secret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'services.turnstile.secret_key'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Off until both keys exist, so a half-configured deploy can't lock readers out.&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;blank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$secret&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nf"&gt;blank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'services.turnstile.site_key'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'cf-turnstile-response'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$token&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Http&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;asForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://challenges.cloudflare.com/turnstile/v0/siteverify'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'secret'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$secret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'response'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'remoteip'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="nc"&gt;Throwable&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// fail closed if Cloudflare can't be reached&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'success'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(The real method also logs each rejection. I've cut the logging here.)&lt;/p&gt;

&lt;p&gt;Two decisions in there are worth defending. A failed Turnstile check returns a real 422 error, not the fake success the block list uses. A real reader can fail Turnstile (an expired token, a flaky connection), and they need to see an error and try again. Only bots fill the honeypot or use a blocked domain, so lying to them costs nothing. And when Cloudflare can't be reached, the signup is refused. A few lost signups during an outage cost me much less than a stream of bot signups.&lt;/p&gt;

&lt;p&gt;On the page, the widget doesn't load until someone clicks into the form. Most readers never subscribe, so most page views never download Cloudflare's script. It renders with &lt;code&gt;appearance: 'interaction-only'&lt;/code&gt;, which keeps it invisible unless Cloudflare wants a click:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;startTurnstile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;siteKey&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;started&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;started&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;loadTurnstile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;widgetId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;turnstile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'#newsletter-turnstile'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;sitekey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;siteKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'newsletter'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;appearance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'interaction-only'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="c1"&gt;// trimmed: the real callback also wakes a submit that is waiting for a token&lt;/span&gt;
            &lt;span class="n"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'expired-callback'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'focusin'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;startTurnstile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details from the &lt;a href="https://developers.cloudflare.com/turnstile/get-started/server-side-validation/" rel="noopener noreferrer"&gt;server-side validation docs&lt;/a&gt; shaped the rest. A token is valid for 300 seconds, and it's meant to be used once. So the submit handler waits for a token if the reader is faster than the check, and calls &lt;code&gt;turnstile.reset()&lt;/code&gt; after every submit to get a fresh one.&lt;/p&gt;

&lt;p&gt;For local testing, Cloudflare publishes &lt;a href="https://developers.cloudflare.com/turnstile/troubleshooting/testing/" rel="noopener noreferrer"&gt;dummy keys&lt;/a&gt;. With site key &lt;code&gt;1x00000000000000000000BB&lt;/code&gt; and secret &lt;code&gt;2x0000000000000000000000000000000AA&lt;/code&gt; the check always fails, so I could watch the whole rejection path in a real browser without touching production. With the &lt;code&gt;1x...AA&lt;/code&gt; secret it always passes.&lt;/p&gt;

&lt;p&gt;Turnstile went live on the morning of 19 November. By the next morning it had rejected 13 attempts, every one of them without a token, because the bot never runs the page. Those 13 were all the bot's tries with domains the block list didn't know.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where each attempt stopped
&lt;/h2&gt;

&lt;p&gt;Put together, the form now has five checks in a row. Each one catches something the others miss, and the three that did nothing this time still earn their place against dumber bots.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-newsletter-subscription-bombing-turnstile" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The order matters for cost. The honeypot, validation and block list are free, so they run first. A request that a cheap check already rejects never costs a call to Cloudflare.&lt;/p&gt;

&lt;h2&gt;
  
  
  The layer I should have had from day one
&lt;/h2&gt;

&lt;p&gt;All of this protects my form from bots. None of it stops a human who types someone else's address into it. Double opt-in does. With it on, Kit emails every new signup a confirmation link, and the address gets no broadcasts until someone clicks it. Someone whose address was submitted by a bot never clicks.&lt;/p&gt;

&lt;p&gt;In Kit, it's in each form's settings, under the Confirmation Email tab. Leave "Auto-confirm new subscribers" unchecked and keep "Send confirmation email" on. Kit's &lt;a href="https://help.kit.com/en/articles/2502655-the-confirmation-email" rel="noopener noreferrer"&gt;help article&lt;/a&gt; recommends leaving auto-confirm off.&lt;/p&gt;

&lt;p&gt;It isn't free either. Each victim still gets one email from me, the confirmation, which is exactly what a subscription bomber wants. That's why it comes after Turnstile, not instead of it. Turnstile stops the email from being sent. Double opt-in makes sure that if one does get through, it's the only one. And my &lt;code&gt;confirmed&lt;/code&gt; status needs renaming, because "Kit accepted it" and "the person confirmed" stop being the same thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Why would anyone use a small blog's newsletter form for this?
&lt;/h3&gt;

&lt;p&gt;Because the attack needs breadth, not reach. Each form contributes one email per victim, and a small form with no CAPTCHA is easier to automate than a big one. The test signup on a catch-all domain two days earlier was the bot checking that my form qualified.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is a honeypot enough to stop newsletter spam?
&lt;/h3&gt;

&lt;p&gt;No, though it's still worth having. It stops bots that fill every field, which is a lot of them. It didn't catch a single one of these. &lt;a href="https://github.com/spatie/laravel-honeypot" rel="noopener noreferrer"&gt;spatie/laravel-honeypot&lt;/a&gt; adds a timing check on top, rejecting forms submitted faster than one second by default. That helps against fast bots, but this one was slow on purpose.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does Turnstile require my site to be on Cloudflare?
&lt;/h3&gt;

&lt;p&gt;No. Cloudflare's docs say Turnstile works on any site without sending traffic through Cloudflare, and the free plan covers it. You need a widget in the Cloudflare dashboard for your hostname, a site key in the page, and a secret key in the server's &lt;code&gt;.env&lt;/code&gt;. If a team shares that file, &lt;a href="https://hafiz.dev/blog/laravel-env-encrypt-share-secrets-team" rel="noopener noreferrer"&gt;encrypt it&lt;/a&gt; instead of pasting the key into Slack.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should a blocked signup get an error or a fake success?
&lt;/h3&gt;

&lt;p&gt;It depends on who can trigger it. Fake success suits checks that only a bot can fail, like a filled honeypot or a blocked domain, because it gives the bot nothing to adapt to. Anything a real person can fail, like an expired Turnstile token, needs a real error.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd do on day one now
&lt;/h2&gt;

&lt;p&gt;If I were building this form again, I'd start with Turnstile verified on the server and double opt-in in the email provider, and treat the honeypot and the throttle as extras. A block list is still handy, but as an emergency tool for the morning an attack starts, not as the plan. The bot is still trying as I write this. It just doesn't get anywhere, and the only sign is a log line every quarter of an hour or so.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>security</category>
      <category>cloudflare</category>
      <category>botprotection</category>
    </item>
    <item>
      <title>PHP 8.3.37 Fixed 5 Critical Bugs on 19 November. Which Ones Reach a Laravel App?</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Mon, 23 Nov 2026 05:15:11 +0000</pubDate>
      <link>https://dev.to/hafiz619/php-8337-fixed-5-critical-bugs-on-19-november-which-ones-reach-a-laravel-app-31d7</link>
      <guid>https://dev.to/hafiz619/php-8337-fixed-5-critical-bugs-on-19-november-which-ones-reach-a-laravel-app-31d7</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/php-8-3-37-critical-fixes-laravel" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;On 19 November PHP shipped 8.5.13, 8.4.28, 8.3.37 and 8.2.36, alongside the first stable 8.6.0. The &lt;a href="https://www.php.net/ChangeLog-8.php#8.3.37" rel="noopener noreferrer"&gt;8.3.37 changelog&lt;/a&gt; lists 13 security fixes. Five of them are rated critical, every one at 9.2 on CVSS v4. My production server, a single Ubuntu box with several sites behind nginx and PHP-FPM, was still on 8.3.36 the next morning.&lt;/p&gt;

&lt;p&gt;I patched it. But first I read every critical advisory and asked one question of each. What would an attacker need from a Laravel app for this to work?&lt;/p&gt;

&lt;p&gt;The answer surprised me a little. Most of them need something a stock Laravel app never does. And the ones that could still matter depend on what else shares the server, not on Laravel. One setting even changed during the upgrade, although nobody touched php.ini.&lt;/p&gt;

&lt;h2&gt;
  
  
  What shipped for PHP 8.3
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://www.php.net/releases/8_3_37.php" rel="noopener noreferrer"&gt;release announcement&lt;/a&gt; is short. It says this is a security release and encourages all 8.3 users to upgrade. The detail lives in the changelog and the &lt;a href="https://github.com/php/php-src/security/advisories" rel="noopener noreferrer"&gt;php-src security advisories&lt;/a&gt;. Three of the five critical fixes are in ext-session, PHP's own session extension. One is in ext-date and one is in PHP-FPM.&lt;/p&gt;

&lt;p&gt;Laravel has its own session layer. It never calls &lt;code&gt;session_start()&lt;/code&gt;, and its drivers (file, database, redis, cookie) are its own classes. I checked the 13.x branch of &lt;code&gt;laravel/framework&lt;/code&gt; to be sure. There isn't a single &lt;code&gt;session_start(&lt;/code&gt; call under &lt;code&gt;src/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So for each fix, the question becomes concrete. Does the bug need PHP's native session machinery, a specific php.ini, or a specific web server setup?&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;th&gt;Where&lt;/th&gt;
&lt;th&gt;What an attacker needs&lt;/th&gt;
&lt;th&gt;Default Laravel app on nginx&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://github.com/php/php-src/security/advisories/GHSA-658j-r8rw-q6mx" rel="noopener noreferrer"&gt;Session serializer mismatch&lt;/a&gt; (CVE-2026-115560)&lt;/td&gt;
&lt;td&gt;ext-session&lt;/td&gt;
&lt;td&gt;Upload progress on, plus something that later reads that native session with the &lt;code&gt;php&lt;/code&gt; serializer and has a gadget chain&lt;/td&gt;
&lt;td&gt;The write half works. Nothing reads it back&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://github.com/php/php-src/security/advisories/GHSA-fm2m-fjf5-v3cp" rel="noopener noreferrer"&gt;Partially overwritten session files&lt;/a&gt; (CVE-2026-126714)&lt;/td&gt;
&lt;td&gt;ext-session&lt;/td&gt;
&lt;td&gt;Native file sessions, attacker influence over session data, an interrupted write&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://github.com/php/php-src/security/advisories/GHSA-g3vh-838c-65v7" rel="noopener noreferrer"&gt;Use-after-free after interrupted session shutdown&lt;/a&gt; (CVE-2026-129481)&lt;/td&gt;
&lt;td&gt;ext-session&lt;/td&gt;
&lt;td&gt;A native session whose cleanup hits a fatal error, then any next request on the same worker&lt;/td&gt;
&lt;td&gt;Not from Laravel itself. A shared pool changes that&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://github.com/php/php-src/security/advisories/GHSA-gr4f-wgx5-jpfv" rel="noopener noreferrer"&gt;Timezone cache use-after-free&lt;/a&gt; (CVE-2026-129496)&lt;/td&gt;
&lt;td&gt;ext-date&lt;/td&gt;
&lt;td&gt;A startup warning written to a file-based &lt;code&gt;error_log&lt;/code&gt;, then an early diagnostic in a fresh worker&lt;/td&gt;
&lt;td&gt;Depends on php.ini, not on Laravel&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://github.com/php/php-src/security/advisories/GHSA-qc49-hpvq-g2w6" rel="noopener noreferrer"&gt;PHP-FPM request smuggling&lt;/a&gt; (CVE-2026-129289)&lt;/td&gt;
&lt;td&gt;PHP-FPM&lt;/td&gt;
&lt;td&gt;Persistent FastCGI connections from the front end, plus a code path that opens &lt;code&gt;php://input&lt;/code&gt; and doesn't read it to the end&lt;/td&gt;
&lt;td&gt;No, with nginx's defaults&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The other eight fixes in the 8.3 branch cover SOAP, Phar signatures, the FPM status page, PHP-CGI and the HTTP stream wrappers. Four of them are rated high. Worth patching, but none of them is the reason to patch today.&lt;/p&gt;

&lt;h2&gt;
  
  
  The session bugs live in code Laravel never runs
&lt;/h2&gt;

&lt;p&gt;The serializer mismatch is the one with the scariest headline, so I started there. PHP's session upload progress feature tracks a running upload by writing progress data into the visitor's session. The &lt;a href="https://www.php.net/manual/en/session.upload-progress.php" rel="noopener noreferrer"&gt;PHP manual&lt;/a&gt; says plainly when that happens. "The upload progress information is written to the session before any scripts are executed."&lt;/p&gt;

&lt;p&gt;Read that twice. It doesn't matter that Laravel never starts a native session. If &lt;code&gt;session.upload_progress.enabled&lt;/code&gt; is on, a multipart POST with the right field name and a &lt;code&gt;PHPSESSID&lt;/code&gt; cookie makes PHP write attacker-chosen file and field names into a session file under &lt;code&gt;session.save_path&lt;/code&gt;. Your app code hasn't even loaded yet.&lt;/p&gt;

&lt;p&gt;That's only half the attack, though. The advisory needs a second step, something that reads the same stored session with a different serializer and then deserializes it with a gadget chain available. In a Laravel app nothing reads &lt;code&gt;/var/lib/php/sessions&lt;/code&gt;. Laravel's file driver writes to &lt;code&gt;storage/framework/sessions&lt;/code&gt; through its own handler.&lt;/p&gt;

&lt;p&gt;So what reads native sessions on a typical Laravel server? Usually nothing. On my box the native session directory was empty:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ ls /var/lib/php/sessions &lt;span class="o"&gt;|&lt;/span&gt; wc -l
0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But a server that also hosts a WordPress site, an old admin panel or a phpMyAdmin install is a different story. Those use native sessions. The partially overwritten session files bug needs the same thing, native file sessions with attacker influence over the data.&lt;/p&gt;

&lt;p&gt;The interrupted shutdown use-after-free is the subtle one. It's an incomplete fix for one of October's advisories (CVE-2026-109619), and it says outright that disabling upload progress does nothing for it. It needs a native session whose cleanup hits a fatal error. Then the next request on the same FPM worker touches freed memory, and that request doesn't need to belong to the same user or the same site. My server runs every site in one FPM pool called &lt;code&gt;www&lt;/code&gt;. So if any of those sites used native sessions, a Laravel site sharing the worker would inherit the problem. The advisory says it could lead to code execution, although that hasn't been demonstrated yet. But "shared worker" is exactly the kind of detail I'd rather not argue about.&lt;/p&gt;

&lt;h2&gt;
  
  
  Request smuggling needs a front end Laravel doesn't control
&lt;/h2&gt;

&lt;p&gt;PHP reads &lt;code&gt;php://input&lt;/code&gt; lazily. If a code path opens the stream and stops early (the advisory's example is a malformed multipart body that makes PHP's parser stop at a predictable position), the rest of the body stays unread on the connection.&lt;/p&gt;

&lt;p&gt;On a normal nginx setup that's harmless. nginx closes the FastCGI connection after each request, and the leftover bytes go with it. With persistent connections they don't. The leftover bytes get parsed as the next FastCGI request, and an attacker can forge its parameters, including &lt;code&gt;PHP_ADMIN_VALUE&lt;/code&gt; settings like &lt;code&gt;auto_prepend_file&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/php-8-3-37-critical-fixes-laravel" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So the check is one grep. Is anything keeping FastCGI connections open?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ grep -rn &lt;span class="s2"&gt;"fastcgi_keep_conn"&lt;/span&gt; /etc/nginx/
$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No output on my server. &lt;a href="https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_keep_conn" rel="noopener noreferrer"&gt;&lt;code&gt;fastcgi_keep_conn&lt;/code&gt;&lt;/a&gt; defaults to off, so every site there closes the connection after each request. The advisory also names Apache's &lt;code&gt;mod_proxy_fcgi&lt;/code&gt; with &lt;code&gt;enablereuse=on&lt;/code&gt;, HAProxy FastCGI backends and LSAPI. If you run any of those, this is the fix to apply first.&lt;/p&gt;

&lt;p&gt;The Laravel side helps a little too. Symfony's &lt;code&gt;Request::getContent()&lt;/code&gt; reads &lt;code&gt;php://input&lt;/code&gt; to the end with &lt;code&gt;file_get_contents()&lt;/code&gt;, unless you explicitly ask for a stream resource. But the advisory warns that reading the whole body may not be a reliable mitigation on its own. So the front end setting is the one I'd check.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I patched the server
&lt;/h2&gt;

&lt;p&gt;The server uses Ondřej Surý's PPA, so the fix arrived as 16 &lt;code&gt;php8.3&lt;/code&gt; packages. I wanted three things. A way back, no surprise config changes, and proof afterwards that every PHP process was on the new binary.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Back up the PHP config, then list the packages and dry-run the upgrade:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tar -czf /root/php-config-backup-&lt;span class="nv"&gt;$(&lt;/span&gt;date -u +%Y%m%d-%H%M%S&lt;span class="o"&gt;)&lt;/span&gt;.tar.gz /etc/php/8.3
&lt;span class="nv"&gt;PKGS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;apt list --upgradable 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;|&lt;/span&gt; grep -oE &lt;span class="s1"&gt;'^php8\.3[^/]*'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; tr &lt;span class="s1"&gt;'\n'&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
apt-get -s install --only-upgrade &lt;span class="nv"&gt;$PKGS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dry run showed 16 upgrades, nothing new installed and nothing removed.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Upgrade, keeping every existing config file:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;DEBIAN_FRONTEND&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;noninteractive &lt;span class="nv"&gt;UCF_FORCE_CONFFOLD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 \
  apt-get install -y --only-upgrade \
  -o Dpkg::Options::=&lt;span class="s2"&gt;"--force-confdef"&lt;/span&gt; \
  -o Dpkg::Options::=&lt;span class="s2"&gt;"--force-confold"&lt;/span&gt; &lt;span class="nv"&gt;$PKGS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tail of the output had something I didn't ask for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Setting up php8.3-fpm (8.3.37-2+ubuntu24.04.1+deb.sury.org+1) ...
Setting up php8.3 (8.3.37-2+ubuntu24.04.1+deb.sury.org+1) ...
 systemctl restart supervisor.service
Service restarts being deferred:
 /etc/needrestart/restart.d/dbus.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ubuntu's &lt;code&gt;needrestart&lt;/code&gt; saw that supervisor's children were running the old PHP binary and restarted supervisor on its own. That restarts every queue worker on the box. It's the right outcome (a worker on the old binary is still unpatched), but it happens mid-upgrade, whether or not a job is running. Laravel workers finish the current job when they get SIGTERM, as long as supervisor's &lt;code&gt;stopwaitsecs&lt;/code&gt; is longer than your slowest job. I wrote about that in &lt;a href="https://hafiz.dev/blog/laravel-queue-worker-sigterm-interruptible-jobs" rel="noopener noreferrer"&gt;what happens to a running job when the worker stops&lt;/a&gt;. Check that setting before you patch, not after.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Verify. Both binaries report 8.3.37, and no FPM process is left on the old one:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ php-fpm8.3 -v &lt;span class="o"&gt;|&lt;/span&gt; head -1
PHP 8.3.37 &lt;span class="o"&gt;(&lt;/span&gt;fpm-fcgi&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;built: Nov 19 2026 20:02:49&lt;span class="o"&gt;)&lt;/span&gt;
$ &lt;span class="k"&gt;for&lt;/span&gt; p &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;pgrep -f php-fpm&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; readlink /proc/&lt;span class="nv"&gt;$p&lt;/span&gt;/exe&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sort &lt;span class="o"&gt;|&lt;/span&gt; uniq -c
      5 /usr/sbin/php-fpm8.3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A process still on a replaced binary shows up there with &lt;code&gt;(deleted)&lt;/code&gt; after the path. Then I extracted the backup and ran &lt;code&gt;diff -rq&lt;/code&gt; against &lt;code&gt;/etc/php/8.3&lt;/code&gt;. Identical. Every site returned 200 before and after.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setting that changed under an untouched php.ini
&lt;/h2&gt;

&lt;p&gt;One more detail from the verification. In October, after the previous session advisory, I'd added a one-line override for FPM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c1"&gt;; /etc/php/8.3/fpm/conf.d/99-upload-progress.ini
&lt;/span&gt;&lt;span class="na"&gt;session.upload_progress.enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Off&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CLI has no such file. Its &lt;code&gt;php.ini&lt;/code&gt; has the line commented out (&lt;code&gt;;session.upload_progress.enabled = On&lt;/code&gt;), so the CLI uses PHP's compiled default. Before the upgrade, &lt;code&gt;php -i&lt;/code&gt; on the CLI reported &lt;code&gt;On&lt;/code&gt;. The upgrade kept php.ini byte for byte, as the diff confirmed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/php-8-3-37-critical-fixes-laravel" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ php -i &lt;span class="o"&gt;|&lt;/span&gt; grep &lt;span class="s1"&gt;'^session.upload_progress.enabled'&lt;/span&gt;
session.upload_progress.enabled &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; Off &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; Off
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The compiled default flipped. The serializer mismatch advisory says the fix disables session upload progress by default, and the binary agrees. The &lt;a href="https://www.php.net/manual/en/session.configuration.php" rel="noopener noreferrer"&gt;configuration page of the PHP manual&lt;/a&gt; still says it defaults to 1 at the time of writing, so don't trust the manual for this one. Trust &lt;code&gt;php -i&lt;/code&gt;. I'm keeping the explicit &lt;code&gt;Off&lt;/code&gt; for FPM anyway. A default can flip back on a rebuild, a different PPA or a different branch, and an explicit line in &lt;code&gt;conf.d&lt;/code&gt; survives all of them.&lt;/p&gt;

&lt;p&gt;Nothing on my server uses upload progress, and in a Laravel app you probably don't either. Upload progress bars in the browser come from XHR's upload progress events, which need nothing from PHP. (I covered the Laravel side of big uploads in &lt;a href="https://hafiz.dev/blog/handling-large-file-uploads-in-laravel-without-crashing-your-server" rel="noopener noreferrer"&gt;handling large file uploads without crashing your server&lt;/a&gt;.)&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Does Laravel use PHP's native sessions?
&lt;/h3&gt;

&lt;p&gt;No. Laravel's session layer is its own &lt;code&gt;Store&lt;/code&gt; class with its own drivers, and the framework never calls &lt;code&gt;session_start()&lt;/code&gt;. That's why most of the ext-session fixes in this release don't reach Laravel code directly. The exception is upload progress, which PHP handles before any script runs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should I turn off session.upload_progress?
&lt;/h3&gt;

&lt;p&gt;Yes, unless something on the server uses it, and Laravel apps rarely do. The fixed releases already default it to off, but an explicit &lt;code&gt;session.upload_progress.enabled = Off&lt;/code&gt; in your FPM &lt;code&gt;conf.d&lt;/code&gt; keeps it off whatever the default does later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need to restart queue workers after a PHP upgrade?
&lt;/h3&gt;

&lt;p&gt;Yes. A long-running &lt;code&gt;queue:work&lt;/code&gt; process keeps the old PHP binary in memory until it restarts. On Ubuntu, &lt;code&gt;needrestart&lt;/code&gt; may restart supervisor for you during the upgrade, as it did for me. Elsewhere, restart them yourself, and make sure &lt;code&gt;stopwaitsecs&lt;/code&gt; lets running jobs finish.&lt;/p&gt;

&lt;h3&gt;
  
  
  I'm on Laravel Forge or Laravel Cloud. Do I need to do anything?
&lt;/h3&gt;

&lt;p&gt;Securing Laravel's &lt;a href="https://securinglaravel.com/security-notice-critical-php-security-release-19th-nov/" rel="noopener noreferrer"&gt;notice before the release&lt;/a&gt; said Laravel would contact Forge, Cloud and Vapor users with the steps. On Forge you still own the server, so check the PHP version yourself with &lt;code&gt;php -v&lt;/code&gt; and &lt;code&gt;php-fpm8.3 -v&lt;/code&gt; (or your version's binary) instead of assuming.&lt;/p&gt;

&lt;h2&gt;
  
  
  Patch it anyway
&lt;/h2&gt;

&lt;p&gt;None of this is a reason to wait. "My Laravel app doesn't reach it" is true for a clean server, and very few servers stay clean. A second site in the same FPM pool, a forgotten phpMyAdmin, someone enabling &lt;code&gt;fastcgi_keep_conn&lt;/code&gt; for a benchmark next year. Each of those quietly turns a "no" in that table into a "yes".&lt;/p&gt;

&lt;p&gt;What the analysis does tell you is where to look while you patch. Three checks cover most of it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;grep -rn &lt;span class="s2"&gt;"fastcgi_keep_conn\|enablereuse"&lt;/span&gt; /etc/nginx/ /etc/apache2/ 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
php-fpm8.3 -i &lt;span class="o"&gt;|&lt;/span&gt; grep -E &lt;span class="s1"&gt;'^(session\.upload_progress\.enabled|session\.save_path|error_log|date\.timezone) '&lt;/span&gt;
ls /var/lib/php/sessions &lt;span class="o"&gt;|&lt;/span&gt; wc -l
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first finds persistent FastCGI connections. The second shows the upload progress setting, where native sessions live, and whether startup warnings go to a file (the timezone bug needs that). The third tells you whether anything on the box uses native sessions at all.&lt;/p&gt;

&lt;p&gt;My own answers were no keep-alive, upload progress off, and an empty session directory. &lt;code&gt;error_log&lt;/code&gt; is unset, so startup warnings go to FPM's own log, which the timezone advisory says doesn't meet its condition. So the box wasn't exposed to the demonstrated attacks, and it's patched now regardless. The rest of that server's setup is in &lt;a href="https://hafiz.dev/blog/how-i-hardened-my-vps-ssh-cloudflare-tailscale" rel="noopener noreferrer"&gt;how I hardened my VPS with SSH keys, Cloudflare and Tailscale&lt;/a&gt;. For the dependency side of fast security fixes, see &lt;a href="https://hafiz.dev/blog/composer-2-11-cooldown-laravel" rel="noopener noreferrer"&gt;Composer 2.11's cooldown&lt;/a&gt;, which holds back security releases too.&lt;/p&gt;

&lt;p&gt;What I'm changing next is the one-pool-for-everything setup. With a separate FPM pool per site, a native session in one app can't leave freed memory for a request from another, and the interrupted shutdown bug would never have been a question.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>security</category>
      <category>devops</category>
    </item>
    <item>
      <title>What /up Cannot See: The Daily Health Check Behind My Laravel App, and the 3 Bugs It Had First</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Thu, 19 Nov 2026 05:15:10 +0000</pubDate>
      <link>https://dev.to/hafiz619/what-up-cannot-see-the-daily-health-check-behind-my-laravel-app-and-the-3-bugs-it-had-first-1d9c</link>
      <guid>https://dev.to/hafiz619/what-up-cannot-see-the-daily-health-check-behind-my-laravel-app-and-the-3-bugs-it-had-first-1d9c</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/laravel-health-check-beyond-up" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;On 9 May, the queued jobs on hafiz.dev started failing and kept failing for the rest of the day. The newsletter send failed. The Dev.to cross-post failed. The homepage answered 200 the whole time, so anything watching it from the outside would have shown green. The cause was a duplicate &lt;code&gt;schedule:run&lt;/code&gt; line I had added to root's crontab while checking the scheduler.&lt;/p&gt;

&lt;p&gt;That's the gap between "the site is up" and "the app works". Laravel's &lt;code&gt;/up&lt;/code&gt; route sits on the first side of it. So in October I wrote a daily check for the second side, called &lt;code&gt;ops:health&lt;/code&gt;, that runs inside the app as the web user and sends a Telegram message only when something fails.&lt;/p&gt;

&lt;p&gt;It had three bugs in its first week, all mine.&lt;/p&gt;

&lt;h2&gt;
  
  
  What /up actually checks
&lt;/h2&gt;

&lt;p&gt;Every new Laravel 11+ app registers &lt;code&gt;/up&lt;/code&gt; in &lt;code&gt;bootstrap/app.php&lt;/code&gt;. Here's the controller behind it, &lt;code&gt;Illuminate\Foundation\Http\HealthCheck&lt;/code&gt;, as of 13.42:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;__invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$exception&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DiagnosingHealth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="nc"&gt;Throwable&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;app&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasDebugModeEnabled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nf"&gt;report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nv"&gt;$exception&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$exception&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// ... renders health-up.blade.php, or JSON, with that status&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all of it. The framework booted, an event fired, and nothing threw. There's no database query in there unless you add one with a &lt;code&gt;DiagnosingHealth&lt;/code&gt; listener.&lt;/p&gt;

&lt;p&gt;That's fine for a load balancer, which only needs to know whether to send traffic. It's also what an external uptime monitor sees when it pings your homepage. Neither one runs a queued job or looks at who owns your log file.&lt;/p&gt;

&lt;h2&gt;
  
  
  The failure behind a green 200
&lt;/h2&gt;

&lt;p&gt;Laravel's &lt;code&gt;daily&lt;/code&gt; log channel creates a new file on the first write of the day, and whoever writes first owns it. In May that was root. The duplicate cron line ran &lt;code&gt;schedule:run&lt;/code&gt; as root, a scheduled command wrote a log line, and from then on &lt;code&gt;www-data&lt;/code&gt; could read the day's log but not append to it.&lt;/p&gt;

&lt;p&gt;To show it step by step, I reproduced it in a &lt;code&gt;php:8.4-cli&lt;/code&gt; container with a fresh Laravel 13.42 app, its &lt;code&gt;storage&lt;/code&gt; owned by &lt;code&gt;www-data&lt;/code&gt;. As root, one artisan command wrote one log line. Then, as &lt;code&gt;www-data&lt;/code&gt;, a queue worker picked up a job that logs one line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  2026-11-13 11:13:50 App\Jobs\SendNewsletter ........................ RUNNING
  2026-11-13 11:13:50 App\Jobs\SendNewsletter .................... 9.70ms FAIL

   UnexpectedValueException

  The stream or file "/app/storage/logs/laravel-2026-11-13.log" could not be opened in
  append mode: Failed to open stream: Permission denied
  The exception occurred while attempting to log: Newsletter sent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The job failed on its only log line. The worker's attempt to report that failure hit the same file, and the &lt;code&gt;queue:work --once&lt;/code&gt; process exited with code 1. The job did land in &lt;code&gt;failed_jobs&lt;/code&gt;. And a request for &lt;code&gt;/&lt;/code&gt;, handled as &lt;code&gt;www-data&lt;/code&gt; in the same container, returned 200, because rendering that page never writes to the log.&lt;/p&gt;

&lt;p&gt;That's the May incident in one container. In production it lasted until I noticed and ran &lt;code&gt;chown&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What a log-based alert sees
&lt;/h3&gt;

&lt;p&gt;The obvious alert is "tell me when errors show up in the log". So what did the log hold after that failure?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-health-check-beyond-up" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -l storage/logs/
-rw-r--r-- 1 root root 63 Nov 13 11:13 laravel-2026-11-13.log

$ cat storage/logs/laravel-2026-11-13.log
[2026-11-13 11:13:43] local.INFO: checking something as root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing new. Root's one line, 63 bytes, and no other file. Every attempt to record the failure needed the file that was broken, so the errors had nowhere to go. Laravel does have an emergency logger, but &lt;code&gt;LogManager&lt;/code&gt; only uses it when a channel can't be created. Here the channel was created fine and the write failed.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ops:health&lt;/code&gt; also reads the &lt;code&gt;failed_jobs&lt;/code&gt; table, where the job did land. And it checks the paths &lt;code&gt;www-data&lt;/code&gt; needs to write, including today's log file (trimmed):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$paths&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;storage_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'logs'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;storage_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'logs/laravel-'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y-m-d'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'.log'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;storage_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'framework/views'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;storage_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'app/public'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nf"&gt;base_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'bootstrap/cache'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$paths&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;file_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nf"&gt;is_writable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;posix_getpwuid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;fileowner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;'?'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"storage: {$path} is not writable (owner {$owner})"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;is_writable()&lt;/code&gt; answers for the user running the check, and running things as root is what caused the incident in the first place. In the container, on the root-owned log:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root:     bool(true)
www-data: bool(false)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the check as root and it passes on the exact file that's broken. So the command warns when it starts as root, and I only ever run it with &lt;code&gt;sudo -u www-data&lt;/code&gt;. The scheduled run already does, because &lt;code&gt;schedule:run&lt;/code&gt; lives in the &lt;code&gt;www-data&lt;/code&gt; crontab. The &lt;a href="https://github.com/backstagephp/laravel-ok" rel="noopener noreferrer"&gt;laravel-ok&lt;/a&gt; package has a Permission Check with the same trap. Its README says it checks permissions "for the current user", so it's only as honest as the user you run it as.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the daily check looks at
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ops:health&lt;/code&gt; is one artisan command, about 370 lines, with no package behind it. In order:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Log errors&lt;/strong&gt; in the last 24 hours, grouped by message, top three reported.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Failed jobs&lt;/strong&gt;, with the newest job's class and time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stale queue&lt;/strong&gt;: any job waiting more than 15 minutes means the worker isn't running.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scheduled posts&lt;/strong&gt; still unpublished 15 minutes after their time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every published post&lt;/strong&gt; renders without an error, without a broken component, and with every image it shows present on disk. A broken post still answers 200, and posts are what this site is for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scheduler heartbeat&lt;/strong&gt; younger than 15 minutes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage&lt;/strong&gt; writable by the web user, as above.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Disk&lt;/strong&gt; above 10% free.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key pages&lt;/strong&gt; answering 200, which is the uptime-monitor part, done from inside.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It runs from the scheduler every morning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Schedule&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;file_put_contents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OpsHealth&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;heartbeatPath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;toIso8601String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;everyFiveMinutes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ops-heartbeat'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Schedule&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ops:health --notify'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;dailyAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'07:00'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;onFailure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ops:health found failures'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--notify&lt;/code&gt; sends one Telegram message listing the failures, and nothing when every check passes. A message that arrives every morning gets ignored by the third morning, so silence has to mean healthy.&lt;/p&gt;

&lt;p&gt;That rule is also how I found the bugs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three bugs it had in its first week
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Scanner noise looked like errors
&lt;/h3&gt;

&lt;p&gt;The log from 27 October alone held at least 28 Livewire hydration errors. "Cannot update locked property", "Livewire encountered corrupt data", that family. They came from scanners probing &lt;code&gt;/livewire/update&lt;/code&gt; for CVE-2025-54068, and the app runs Livewire 3.6.4, the patched release. So the attempts failed, which is exactly what produced the errors.&lt;/p&gt;

&lt;p&gt;A check that fails on these alerts every day for nothing. Ignoring all Livewire errors would hide a real one. So the command keeps a list of exact message prefixes, counts matches as "scanner errors ignored", and prints the count without failing. A prefix only goes on the list after I've traced it to a scanner.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. The heartbeat lived in the cache, and deploys clear the cache
&lt;/h3&gt;

&lt;p&gt;The first version stored the heartbeat in the cache. &lt;code&gt;deploy.sh&lt;/code&gt; runs &lt;code&gt;php artisan optimize:clear&lt;/code&gt;, which clears the cache, so every deploy deleted the heartbeat (a deploy already does enough to a running app, from clearing caches to the &lt;a href="https://hafiz.dev/blog/laravel-queue-worker-sigterm-interruptible-jobs" rel="noopener noreferrer"&gt;SIGTERM every queue worker gets&lt;/a&gt;). The next check reported a dead scheduler on a server where the scheduler was fine.&lt;/p&gt;

&lt;p&gt;The fix was a plain file in &lt;code&gt;storage/app&lt;/code&gt;, excluded from deploys. If you use &lt;a href="https://spatie.be/docs/laravel-health/v1/available-checks/schedule" rel="noopener noreferrer"&gt;spatie/laravel-health&lt;/a&gt;, its &lt;code&gt;ScheduleCheck&lt;/code&gt; also keeps its heartbeat in the cache. Its docs highly recommend giving it a cache store of its own. I'd follow that advice, and make sure your deploy never clears that store.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. It alerted on its own alert
&lt;/h3&gt;

&lt;p&gt;When a scheduled command exits with a non-zero code, Laravel's scheduler logs an error. &lt;code&gt;ops:health&lt;/code&gt; returns 1 when a check fails, so a failing run leaves this behind:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2026-10-30 07:00:08] production.ERROR: Scheduled command ['/usr/bin/php8.3' 'artisan' ops:health --notify] failed with exit code [1].
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That line sits inside the next run's 24-hour window. So the next morning's run found one error, failed on it, and logged a fresh copy for the morning after. From 30 October to 3 November, the only error each run found was the line the previous run had left.&lt;/p&gt;

&lt;p&gt;The fix skips that one message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Str&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Scheduled command ['&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;str_contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"'artisan' ops:health"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The run that failed already sent its alert. Counting its leftover line again only adds noise. Five mornings, five identical messages.&lt;/p&gt;

&lt;h2&gt;
  
  
  The layer the app can't see
&lt;/h2&gt;

&lt;p&gt;Some failures happen before PHP runs at all. On this server the PHP-FPM pool is shared with other sites. On 3 November a scanner burst hit hafiz.dev, the pool ran out of workers, and the FPM log said so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[03-Nov-2026 14:31:31] WARNING: [pool www] server reached pm.max_children setting (12), consider raising it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While that lasts, requests for every site in the pool wait for a free worker. A request that's still waiting hasn't reached Laravel, so &lt;code&gt;storage/logs&lt;/code&gt; has nothing to say about it, and &lt;code&gt;ops:health&lt;/code&gt; has no way to know. That's why the daily check is only half of it. The other half reads the logs around the app (the FPM log and the nginx error log, filtered to this site) when I check production by hand.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-health-check-beyond-up" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Should you use a package instead?
&lt;/h2&gt;

&lt;p&gt;Maybe. &lt;a href="https://spatie.be/docs/laravel-health/v1/available-checks/overview" rel="noopener noreferrer"&gt;spatie/laravel-health&lt;/a&gt; ships 21 checks, including the database connection, queue, schedule, disk space, debug mode and security advisories. It also gives you a results page, a JSON endpoint and notifications. If you want those, start there.&lt;/p&gt;

&lt;p&gt;None of its built-in checks looks at who owns your files, though, and none of them knows what your app is for. Both packages let you write custom checks, and those are the ones that matter. For this site that's storage writable by &lt;code&gt;www-data&lt;/code&gt;, the failed jobs table, and every published post rendering. For a shop it might be the checkout rendering and yesterday's orders being exported.&lt;/p&gt;

&lt;p&gt;I went with one command because it has no dependencies and I can read all of it in a few minutes. And I knew exactly which failures I was guarding against, because I'd already had them. If you're choosing between tools for the debugging side rather than the alerting side, &lt;a href="https://hafiz.dev/blog/laravel-telescope-vs-pulse-vs-nightwatch" rel="noopener noreferrer"&gt;Telescope, Pulse and Nightwatch&lt;/a&gt; answer different questions from this one.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What does Laravel's /up route check?
&lt;/h3&gt;

&lt;p&gt;It boots the framework and dispatches a &lt;code&gt;DiagnosingHealth&lt;/code&gt; event. It returns 200 if nothing throws and 500 if something does. It doesn't query the database unless you register a &lt;code&gt;DiagnosingHealth&lt;/code&gt; listener that does.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why should health checks run as www-data instead of root?
&lt;/h3&gt;

&lt;p&gt;Because &lt;code&gt;is_writable()&lt;/code&gt; and similar checks answer for the current user, and root can write anywhere. A root-owned file passes the check as root and fails the real app. Running artisan as root can also create the root-owned file you're checking for.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I run artisan as the web user?
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;sudo -u www-data php artisan ...&lt;/code&gt;. For &lt;code&gt;tinker&lt;/code&gt;, add &lt;code&gt;env HOME=/tmp&lt;/code&gt;. Without it, PsySH tries to write its config under the web user's home directory and stops with &lt;code&gt;Writing to directory /var/www/.config/psysh is not allowed&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I keep scanner noise out of a log-based alert?
&lt;/h3&gt;

&lt;p&gt;Match exact message prefixes you've traced, count them, and report the count without failing. Don't ignore a whole package's errors. And keep Livewire and Filament patched, which is what makes the noise harmless in the first place. The &lt;a href="https://hafiz.dev/blog/filament-5-10-security-fixes-livewire-scope-gap" rel="noopener noreferrer"&gt;Filament 5.10 security fixes&lt;/a&gt; are a recent example of why.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should the alert fire every day with a summary?
&lt;/h3&gt;

&lt;p&gt;No. A daily "all good" message trains you to ignore the channel. Send nothing when every check passes, so a message always means something failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two rules for whatever you build
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://hafiz.dev/blog/laravel-slow-job-alerts" rel="noopener noreferrer"&gt;slow job alerts in Laravel 13.40&lt;/a&gt; apply the same thinking one level down, to the job that didn't fail but should still worry you. At either level, run the check as the user the app runs as, and make silence mean healthy.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>monitoring</category>
      <category>devops</category>
      <category>queues</category>
    </item>
    <item>
      <title>I Broke One Laravel Migration on MySQL, PostgreSQL and SQLite. What MigrationFailed in 13.42 Changes</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Mon, 16 Nov 2026 05:15:10 +0000</pubDate>
      <link>https://dev.to/hafiz619/i-broke-one-laravel-migration-on-mysql-postgresql-and-sqlite-what-migrationfailed-in-1342-changes-3p61</link>
      <guid>https://dev.to/hafiz619/i-broke-one-laravel-migration-on-mysql-postgresql-and-sqlite-what-migrationfailed-in-1342-changes-3p61</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/laravel-migrationfailed-half-applied-migrations" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;You fix the duplicate data, run &lt;code&gt;php artisan migrate&lt;/code&gt; again, and Laravel answers with &lt;code&gt;Duplicate column name 'slug'&lt;/code&gt;. The migration failed the first time, so Laravel never recorded it. But half of it ran anyway, and now that half blocks the retry.&lt;/p&gt;

&lt;p&gt;Laravel 13.42 added a &lt;code&gt;MigrationFailed&lt;/code&gt; event for this exact moment (&lt;a href="https://github.com/laravel/framework/pull/62342" rel="noopener noreferrer"&gt;PR #62342&lt;/a&gt;, from Jack Bayliss). It fires when a migration throws and carries the exception. The &lt;a href="https://laravel-news.com/laravel-13-42-0" rel="noopener noreferrer"&gt;release write-up on Laravel News&lt;/a&gt; suggests using it to alert your team before users hit a half-applied schema.&lt;/p&gt;

&lt;p&gt;So which databases actually leave one behind? I ran the same failing migration on MySQL 8.4.13, PostgreSQL 17.12 and SQLite 3.53.4 (the version bundled with PHP 8.4 on my Mac), all on Laravel 13.42.0. They didn't all leave the same mess behind.&lt;/p&gt;

&lt;h2&gt;
  
  
  The migration that fails halfway
&lt;/h2&gt;

&lt;p&gt;It's the classic slug migration. Add a nullable column, backfill it, then add the unique index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;up&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Blueprint&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'slug'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;nullable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;orderBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$product&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'slug'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Str&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$product&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Blueprint&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'slug'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;products&lt;/code&gt; table has three rows: Blue Mug, Red Kettle, and a second Blue Mug (two sizes, same name). The backfill writes &lt;code&gt;blue-mug&lt;/code&gt; twice, so the index can't be built. That's the failure, on purpose. It's also a realistic one, because a duplicate like this shows up in production data and almost never in a seeded local database.&lt;/p&gt;

&lt;h2&gt;
  
  
  MySQL keeps the column, and the retry fails
&lt;/h2&gt;

&lt;p&gt;The first run, with the stack trace trimmed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; 2026_11_14_000002_add_slug_to_products_table .. 32.09ms FAIL

   Illuminate\Database\UniqueConstraintViolationException

  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'blue-mug'
  for key 'products.products_slug_unique' (Connection: mysql, ... SQL: alter table
  `products` add unique `products_slug_unique`(`slug`))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I checked the table and the &lt;code&gt;migrations&lt;/code&gt; table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;hasColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'slug'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;orderBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;pluck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'slug'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;getIndexes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;pluck&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'migrations'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'migration'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'like'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'%add_slug%'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;slug column: true
slugs: ["blue-mug","red-kettle","blue-mug"]
indexes: ["primary"]
recorded: false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The column is there. The backfilled slugs are there. The index isn't, and Laravel has no record that any of it happened. So I renamed the second product to Blue Mug Large and ran &lt;code&gt;migrate&lt;/code&gt; again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; 2026_11_14_000002_add_slug_to_products_table .. 7.97ms FAIL

   Illuminate\Database\QueryException

  SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'slug'
  (Connection: mysql, ... SQL: alter table `products` add `slug` varchar(255) null after `name`)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The data is fixed. The migration still can't run, because its first statement now collides with its own leftovers. From here you drop the column by hand, edit the migration, or insert a fake row into &lt;code&gt;migrations&lt;/code&gt;. None of those belong in a deploy.&lt;/p&gt;

&lt;h2&gt;
  
  
  PostgreSQL rolls the whole thing back
&lt;/h2&gt;

&lt;p&gt;Same migration, same three rows, same failure on the unique index. The state afterwards:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;slug column: false
indexes: ["products_pkey"]
recorded: false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No column, no slugs, no record. After the same rename, the retry just worked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; 2026_11_14_000002_add_slug_to_products_table .. 12.95ms DONE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's the behaviour I'd assumed I was getting everywhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  And SQLite?
&lt;/h2&gt;

&lt;p&gt;New Laravel apps have used SQLite as the default database since &lt;a href="https://laravel.com/docs/11.x/releases" rel="noopener noreferrer"&gt;Laravel 11&lt;/a&gt;, so plenty of local setups run this exact path.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-migrationfailed-half-applied-migrations" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;slug column: true
slugs: ["blue-mug","red-kettle","blue-mug"]
indexes: ["primary"]
recorded: false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SQLite kept everything MySQL kept. The retry failed the same way too, with &lt;code&gt;duplicate column name: slug&lt;/code&gt;. And it isn't because SQLite can't do better. Wrapped in a transaction, SQLite rolled this same migration back completely (that test is further down). Laravel just never opens the transaction.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-migrationfailed-half-applied-migrations" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Where the difference comes from
&lt;/h2&gt;

&lt;p&gt;The answer is a few lines in &lt;code&gt;Illuminate\Database\Migrations\Migrator::runMigration()&lt;/code&gt;, as of 13.42:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getSchemaGrammar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$connection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;supportsSchemaTransactions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$migration&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;withinTransaction&lt;/span&gt;
            &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$connection&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Throwable&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fireMigrationEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MigrationFailed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$migration&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;supportsSchemaTransactions()&lt;/code&gt; reads a &lt;code&gt;$transactions&lt;/code&gt; property on the schema grammar. It's &lt;code&gt;true&lt;/code&gt; in &lt;code&gt;PostgresGrammar&lt;/code&gt; and &lt;code&gt;SqlServerGrammar&lt;/code&gt;. Every other grammar keeps the base class default, which is &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For MySQL that's the honest answer. &lt;a href="https://dev.mysql.com/doc/refman/8.4/en/implicit-commit.html" rel="noopener noreferrer"&gt;Every &lt;code&gt;ALTER TABLE&lt;/code&gt; causes an implicit commit&lt;/a&gt;, so a transaction around the migration wouldn't hold anyway. MariaDB gets the same treatment, because &lt;code&gt;MariaDbGrammar&lt;/code&gt; extends &lt;code&gt;MySqlGrammar&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;SQLite is different. The wrapping arrived in Laravel 5.3 with &lt;a href="https://github.com/laravel/framework/pull/15780" rel="noopener noreferrer"&gt;PR #15780&lt;/a&gt;, and that PR only switched it on for PostgreSQL. Its author said they couldn't test SQL Server and weren't sure SQLite fully supported &lt;code&gt;alter table&lt;/code&gt; inside a transaction. SQL Server got the flag later. SQLite never did.&lt;/p&gt;

&lt;p&gt;So on MySQL and SQLite, each statement runs on its own and commits as it goes. The &lt;code&gt;ALTER TABLE&lt;/code&gt; commits. Each &lt;code&gt;UPDATE&lt;/code&gt; commits. The failing index takes nothing back with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What MigrationFailed actually gives you
&lt;/h2&gt;

&lt;p&gt;The event fires in that &lt;code&gt;catch&lt;/code&gt; block, and where it sits explains how it behaves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On PostgreSQL it fires after the rollback. &lt;code&gt;$connection-&amp;gt;transaction()&lt;/code&gt; has already rolled back and rethrown by the time the &lt;code&gt;catch&lt;/code&gt; runs. A listener I added there saw no &lt;code&gt;slug&lt;/code&gt; column on PostgreSQL.&lt;/li&gt;
&lt;li&gt;The exception is rethrown after the listeners run. So &lt;code&gt;migrate&lt;/code&gt; still exits with 1, and a deploy script running with &lt;code&gt;set -e&lt;/code&gt; still stops.&lt;/li&gt;
&lt;li&gt;It fires for &lt;code&gt;down&lt;/code&gt; as well. &lt;code&gt;migrate:rollback&lt;/code&gt; goes through the same &lt;code&gt;runMigration()&lt;/code&gt;, with &lt;code&gt;$event-&amp;gt;method&lt;/code&gt; set to &lt;code&gt;down&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What it carries is the migration instance, the method, the file name and the exception. Like the &lt;a href="https://hafiz.dev/blog/laravel-slow-job-alerts" rel="noopener noreferrer"&gt;slow job alerts from 13.40&lt;/a&gt;, it reports the moment and leaves the diagnosis to you. It doesn't tell you whether anything was rolled back, or which statements already ran. On MySQL, that second part is what you need to recover.&lt;/p&gt;

&lt;h2&gt;
  
  
  A listener that says what got left behind
&lt;/h2&gt;

&lt;p&gt;This one records schema statements while a migration runs, and logs them only if they survived the failure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Database&lt;/span&gt;\&lt;span class="nc"&gt;Events&lt;/span&gt;\&lt;span class="nc"&gt;MigrationFailed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Database&lt;/span&gt;\&lt;span class="nc"&gt;Events&lt;/span&gt;\&lt;span class="nc"&gt;MigrationStarted&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Database&lt;/span&gt;\&lt;span class="nc"&gt;Events&lt;/span&gt;\&lt;span class="nc"&gt;QueryExecuted&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;boot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;runningInConsole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$statements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MigrationStarted&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nv"&gt;$statements&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$statements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;QueryExecuted&lt;/span&gt; &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nv"&gt;$statements&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;preg_match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/^\s*(alter|create|drop|rename)\b/i'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$statements&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MigrationFailed&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nv"&gt;$statements&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;migration&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getConnection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nv"&gt;$rolledBack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;migration&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;withinTransaction&lt;/span&gt;
            &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$connection&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getSchemaGrammar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;supportsSchemaTransactions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;critical&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Migration [{$event-&amp;gt;name}] failed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'connection'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$connection&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'rolled_back'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$rolledBack&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'already_applied'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$rolledBack&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$statements&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'error'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;exception&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;rolled_back&lt;/code&gt; check copies the Migrator's own condition, so it also covers a migration that sets &lt;code&gt;$withinTransaction = false&lt;/code&gt;. &lt;code&gt;QueryExecuted&lt;/code&gt; only fires for statements that succeeded, so the failing one never lands in the list. Here's what it logged on each database, with the error message cut:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql   {"connection":"mysql","rolled_back":false,"already_applied":["alter table `products` add `slug` varchar(255) null after `name`"]}
pgsql   {"connection":"pgsql","rolled_back":true,"already_applied":[]}
sqlite  {"connection":"sqlite","rolled_back":false,"already_applied":["alter table \"products\" add column \"slug\" varchar"]}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I left the backfill &lt;code&gt;UPDATE&lt;/code&gt;s out on purpose. They committed too, but one line per row is noise in an alert, and the column they wrote to is already in the list. Send the same context to Slack or wherever your alerts go. The log channel is just what I tested with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should the listener put the app down?
&lt;/h2&gt;

&lt;p&gt;The Laravel News example calls &lt;code&gt;Artisan::call('down')&lt;/code&gt; from the listener. I wouldn't do that by default.&lt;/p&gt;

&lt;p&gt;On PostgreSQL there's nothing half-applied, so maintenance mode protects nobody. On MySQL, look at what's actually left here: one extra nullable column. The code that's still running has never heard of it and will keep working. Taking the site down turns a quiet problem into an outage, in the middle of a deploy that already has enough moving parts (your &lt;a href="https://hafiz.dev/blog/laravel-queue-worker-sigterm-interruptible-jobs" rel="noopener noreferrer"&gt;queue workers get a SIGTERM&lt;/a&gt; in that same window).&lt;/p&gt;

&lt;p&gt;The case for &lt;code&gt;down&lt;/code&gt; is a migration that drops or renames something before it fails. The running code does read that column, and it will start throwing. The &lt;code&gt;already_applied&lt;/code&gt; list tells you which case you're in, which is a better trigger than "any migration failed".&lt;/p&gt;

&lt;h2&gt;
  
  
  Make MySQL fail at a clean boundary
&lt;/h2&gt;

&lt;p&gt;A migration only gets a row in &lt;code&gt;migrations&lt;/code&gt; after &lt;code&gt;up()&lt;/code&gt; returns. So the fix on MySQL is to put each statement that can fail in its own migration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2026_11_14_000002_add_slug_column_to_products_table.php
2026_11_14_000003_backfill_product_slugs.php
2026_11_14_000004_add_unique_index_to_product_slugs.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same code as before, split three ways. The same three rows on MySQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; 2026_11_14_000002_add_slug_column_to_products_table .. 16.21ms DONE
 2026_11_14_000003_backfill_product_slugs .. 7.91ms DONE
 2026_11_14_000004_add_unique_index_to_product_slugs .. 13.32ms FAIL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the failure sits on a recorded boundary. The backfill already ran, so the fix has to update the slug as well as the name. After that, &lt;code&gt;migrate&lt;/code&gt; ran only the index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; 2026_11_14_000004_add_unique_index_to_product_slugs .. 32.57ms DONE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No hand-dropped columns, no fake rows in &lt;code&gt;migrations&lt;/code&gt;. Just a data fix and a retry.&lt;/p&gt;

&lt;p&gt;On SQLite you have a second option, because SQLite can roll back DDL. I wrapped the original single migration in a transaction myself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;up&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// the same three steps as before&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On SQLite it failed on the index and left no &lt;code&gt;slug&lt;/code&gt; column behind. On MySQL the same wrapper changed nothing, and the column was still there. I only tested this migration, so try your own riskier SQLite migrations the same way before you rely on it.&lt;/p&gt;

&lt;p&gt;You'll also see &lt;code&gt;Schema::hasColumn()&lt;/code&gt; guards suggested for this. They make a retry pass, but they also hide that the schema drifted, so I'd keep them as a last resort rather than the plan. If you squash migrations, &lt;a href="https://hafiz.dev/blog/laravel-squash-migrations-schema-dump-prune" rel="noopener noreferrer"&gt;the schema:dump --prune post&lt;/a&gt; covers what happens to files like these later.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Does a failed migration get recorded in the migrations table?
&lt;/h3&gt;

&lt;p&gt;No. Laravel writes the row only after &lt;code&gt;up()&lt;/code&gt; returns. In my tests the failed migration had no row on any of the three databases, which is exactly why MySQL and SQLite end up stuck: the schema changed, but the record says it didn't.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does MigrationFailed fire during migrate:rollback?
&lt;/h3&gt;

&lt;p&gt;Yes. Rollbacks run through the same &lt;code&gt;runMigration()&lt;/code&gt; method, so a &lt;code&gt;down()&lt;/code&gt; that throws fires the event with &lt;code&gt;$event-&amp;gt;method&lt;/code&gt; set to &lt;code&gt;down&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is MariaDB the same as MySQL here?
&lt;/h3&gt;

&lt;p&gt;In Laravel, yes. &lt;code&gt;MariaDbGrammar&lt;/code&gt; extends &lt;code&gt;MySqlGrammar&lt;/code&gt; and inherits &lt;code&gt;$transactions = false&lt;/code&gt;, so migrations on MariaDB run without a wrapping transaction.&lt;/p&gt;

&lt;h3&gt;
  
  
  What does $withinTransaction = false do on PostgreSQL?
&lt;/h3&gt;

&lt;p&gt;It turns the wrapping off for that one migration, so it behaves like MySQL. You need it for &lt;code&gt;CREATE INDEX CONCURRENTLY&lt;/code&gt;, which &lt;a href="https://www.postgresql.org/docs/17/sql-createindex.html" rel="noopener noreferrer"&gt;PostgreSQL won't run inside a transaction block&lt;/a&gt;. Keep those migrations to a single statement for the same reason.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I see which statement failed without a listener?
&lt;/h3&gt;

&lt;p&gt;Yes. The &lt;code&gt;QueryException&lt;/code&gt; includes the failing SQL, as in the outputs above. What it can't tell you is which statements before it succeeded. That's the gap the listener fills.&lt;/p&gt;

&lt;h2&gt;
  
  
  One failing statement per migration
&lt;/h2&gt;

&lt;p&gt;On MySQL and SQLite, a Laravel migration isn't a unit. It's a list of statements that commit one at a time, and the first failure leaves the earlier ones in place. So give each migration at most one statement that can fail. Then the retry after a failure is a data fix and nothing else. Bad indexes are the other MySQL trap that only shows up on production data, and &lt;a href="https://hafiz.dev/blog/eloquent-patterns-silently-break-mysql-index" rel="noopener noreferrer"&gt;these six Eloquent patterns&lt;/a&gt; are the ones I check first.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>migrations</category>
      <category>mysql</category>
      <category>laravel13</category>
    </item>
    <item>
      <title>Slow Job Alerts in Laravel 13.40: What whenJobRunsLongerThan Catches and What It Misses</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Thu, 12 Nov 2026 05:15:13 +0000</pubDate>
      <link>https://dev.to/hafiz619/slow-job-alerts-in-laravel-1340-what-whenjobrunslongerthan-catches-and-what-it-misses-1g53</link>
      <guid>https://dev.to/hafiz619/slow-job-alerts-in-laravel-1340-what-whenjobrunslongerthan-catches-and-what-it-misses-1g53</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/laravel-slow-job-alerts" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Laravel 13.40 shipped on 3 November with &lt;code&gt;Queue::whenJobRunsLongerThan()&lt;/code&gt;, a one-liner that tells you when a queued job runs slower than it should. The scheduler got a twin, &lt;code&gt;Schedule::whenTaskRunsLongerThan()&lt;/code&gt;, in the same &lt;a href="https://github.com/laravel/framework/releases/tag/v13.40.0" rel="noopener noreferrer"&gt;release&lt;/a&gt;. The queue docs don't cover either one yet, so I tested them.&lt;/p&gt;

&lt;p&gt;On a fresh Laravel 13.40.0 install with the database queue driver and PHP 8.3, I pushed five jobs through one worker: a fast one, a slow one, one that fails, one that releases itself, and one that runs past the worker's &lt;code&gt;--timeout&lt;/code&gt;. Four did what you'd expect. The fifth is the one to know about before you build alerting on this. All output below is real.&lt;/p&gt;

&lt;h2&gt;
  
  
  What 13.40 added
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/laravel/framework/pull/62141" rel="noopener noreferrer"&gt;PR #62141&lt;/a&gt; adds the queue version. You register it once, in a service provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Carbon&lt;/span&gt;\&lt;span class="nc"&gt;CarbonInterval&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Queue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;boot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Queue&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;whenJobRunsLongerThan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CarbonInterval&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{$job-&amp;gt;resolveName()} took {$duration}ms"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;$duration&lt;/code&gt; is in milliseconds. It comes from the &lt;code&gt;JobAttempted&lt;/code&gt; event, which gained a &lt;code&gt;duration&lt;/code&gt; property in 13.39. And that event is the whole mechanism. This is the core of the method in &lt;code&gt;QueueManager&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'events'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Events&lt;/span&gt;\&lt;span class="nc"&gt;JobAttempted&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$threshold&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$handler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nf"&gt;is_null&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$threshold&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So it isn't a timer. Nothing happens when a running job crosses the threshold. The check runs once, after the attempt is over, and only if a duration was recorded.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five jobs through one worker
&lt;/h2&gt;

&lt;p&gt;The test app registers two thresholds side by side. One uses &lt;code&gt;CarbonInterval::seconds(2)&lt;/code&gt;. The other passes a plain &lt;code&gt;5&lt;/code&gt;, which is easy to type when you mean five seconds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Queue&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;whenJobRunsLongerThan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CarbonInterval&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"[2s threshold] {$job-&amp;gt;resolveName()} took {$duration}ms"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Queue&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;whenJobRunsLongerThan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"[plain 5] {$job-&amp;gt;resolveName()} took {$duration}ms"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The job sleeps, then optionally throws or releases itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;usleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1_000_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s1"&gt;'fail'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RuntimeException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Failed after sleeping'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'release'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;release&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first run is a 0.5 second job, then three 3 second jobs. One finishes, one throws, one releases itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;$ php artisan queue:work --tries=1 --stop-when-empty
 2026-11-06 11:20:35 App\Jobs\SleepJob .. RUNNING
 2026-11-06 11:20:36 App\Jobs\SleepJob .. 514.71ms DONE
 2026-11-06 11:20:36 App\Jobs\SleepJob .. RUNNING
 2026-11-06 11:20:39 App\Jobs\SleepJob .. 3s DONE
 2026-11-06 11:20:39 App\Jobs\SleepJob .. RUNNING
 2026-11-06 11:20:42 App\Jobs\SleepJob .. 3s FAIL
 2026-11-06 11:20:42 App\Jobs\SleepJob .. RUNNING
 2026-11-06 11:20:45 App\Jobs\SleepJob .. 3s RELEASED
 2026-11-06 11:20:48 Worker STOPPED Queue empty
$ grep WARNING storage/logs/laravel.log
&lt;span class="o"&gt;[&lt;/span&gt;2026-11-06 11:20:36&lt;span class="o"&gt;]&lt;/span&gt; local.WARNING: &lt;span class="o"&gt;[&lt;/span&gt;plain 5&lt;span class="o"&gt;]&lt;/span&gt; App\Jobs\SleepJob took 513.2ms
&lt;span class="o"&gt;[&lt;/span&gt;2026-11-06 11:20:39&lt;span class="o"&gt;]&lt;/span&gt; local.WARNING: &lt;span class="o"&gt;[&lt;/span&gt;2s threshold&lt;span class="o"&gt;]&lt;/span&gt; App\Jobs\SleepJob took 3009.45ms
&lt;span class="o"&gt;[&lt;/span&gt;2026-11-06 11:20:39&lt;span class="o"&gt;]&lt;/span&gt; local.WARNING: &lt;span class="o"&gt;[&lt;/span&gt;plain 5&lt;span class="o"&gt;]&lt;/span&gt; App\Jobs\SleepJob took 3009.45ms
&lt;span class="o"&gt;[&lt;/span&gt;2026-11-06 11:20:42&lt;span class="o"&gt;]&lt;/span&gt; local.WARNING: &lt;span class="o"&gt;[&lt;/span&gt;2s threshold&lt;span class="o"&gt;]&lt;/span&gt; App\Jobs\SleepJob took 3003.32ms
&lt;span class="o"&gt;[&lt;/span&gt;2026-11-06 11:20:42&lt;span class="o"&gt;]&lt;/span&gt; local.WARNING: &lt;span class="o"&gt;[&lt;/span&gt;plain 5&lt;span class="o"&gt;]&lt;/span&gt; App\Jobs\SleepJob took 3003.32ms
&lt;span class="o"&gt;[&lt;/span&gt;2026-11-06 11:20:45&lt;span class="o"&gt;]&lt;/span&gt; local.WARNING: &lt;span class="o"&gt;[&lt;/span&gt;2s threshold&lt;span class="o"&gt;]&lt;/span&gt; App\Jobs\SleepJob took 3005.84ms
&lt;span class="o"&gt;[&lt;/span&gt;2026-11-06 11:20:45&lt;span class="o"&gt;]&lt;/span&gt; local.WARNING: &lt;span class="o"&gt;[&lt;/span&gt;plain 5&lt;span class="o"&gt;]&lt;/span&gt; App\Jobs\SleepJob took 3005.84ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 2 second threshold fired for all three slow jobs, including the one that failed and the one that was released. A job that keeps failing slowly and retrying is exactly what you'd want flagged. (13.40 also changed the worker output to say &lt;code&gt;RELEASED&lt;/code&gt; instead of &lt;code&gt;DONE&lt;/code&gt;, which you can see on the last job.)&lt;/p&gt;

&lt;p&gt;The plain &lt;code&gt;5&lt;/code&gt; fired for the 514ms job. That's the unit trap. A plain number is milliseconds here, so &lt;code&gt;whenJobRunsLongerThan(5, ...)&lt;/code&gt; means five milliseconds, and it will fire for almost every job you run.&lt;/p&gt;

&lt;p&gt;And the &lt;code&gt;sync&lt;/code&gt; driver behaves the same way. &lt;code&gt;SleepJob::dispatchSync(3)&lt;/code&gt; logged &lt;code&gt;took 3006.12ms&lt;/code&gt; on both thresholds, because the sync queue dispatches &lt;code&gt;JobAttempted&lt;/code&gt; with a duration too.&lt;/p&gt;

&lt;h2&gt;
  
  
  The scheduler version counts in seconds
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/laravel/framework/pull/62233" rel="noopener noreferrer"&gt;PR #62233&lt;/a&gt; adds &lt;code&gt;Schedule::whenTaskRunsLongerThan()&lt;/code&gt;. Same shape, different unit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Console&lt;/span&gt;\&lt;span class="nc"&gt;Scheduling&lt;/span&gt;\&lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Schedule&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Schedule&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;whenTaskRunsLongerThan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Event&lt;/span&gt; &lt;span class="nv"&gt;$task&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="nv"&gt;$runtime&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{$task-&amp;gt;getSummaryForDisplay()} took {$runtime}s"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here a plain &lt;code&gt;2&lt;/code&gt; means two seconds. So the same number in your queue setup and your scheduler setup means two different things, a thousand times apart. Pass a &lt;code&gt;CarbonInterval&lt;/code&gt; to both and the problem goes away. The queue version converts it with &lt;code&gt;totalMilliseconds&lt;/code&gt; and the scheduler version with &lt;code&gt;totalSeconds&lt;/code&gt;, so &lt;code&gt;CarbonInterval::seconds(30)&lt;/code&gt; means 30 seconds in both places.&lt;/p&gt;

&lt;h2&gt;
  
  
  The job that hits the timeout
&lt;/h2&gt;

&lt;p&gt;The fifth job sleeps for 10 seconds on a worker started with &lt;code&gt;--timeout=5&lt;/code&gt;. It's the slowest job in the whole test, by a distance.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-slow-job-alerts" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;$ php artisan queue:work --tries=1 --timeout=5
 2026-11-06 11:20:18 App\Jobs\SleepJob .. RUNNING
 2026-11-06 11:20:23 App\Jobs\SleepJob .. 5s FAIL
 2026-11-06 11:20:23 Worker STOPPED Job timed out
$ &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
137
$ grep WARNING storage/logs/laravel.log
&lt;span class="o"&gt;[&lt;/span&gt;2026-11-06 11:20:23&lt;span class="o"&gt;]&lt;/span&gt; local.WARNING: &lt;span class="o"&gt;[&lt;/span&gt;timed out&lt;span class="o"&gt;]&lt;/span&gt; App\Jobs\SleepJob after 5s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only the &lt;code&gt;JobTimedOut&lt;/code&gt; listener wrote anything. The worker exited with code 137, which is 128 plus signal 9, &lt;code&gt;SIGKILL&lt;/code&gt;. The order inside &lt;code&gt;Worker::registerTimeoutHandler()&lt;/code&gt; explains it. The &lt;code&gt;SIGALRM&lt;/code&gt; handler marks the job as failed (it's in &lt;code&gt;failed_jobs&lt;/code&gt; as a &lt;code&gt;TimeoutExceededException&lt;/code&gt;), dispatches &lt;code&gt;JobTimedOut&lt;/code&gt;, then calls &lt;code&gt;kill()&lt;/code&gt;, which sends &lt;code&gt;SIGKILL&lt;/code&gt; to its own process. &lt;code&gt;JobAttempted&lt;/code&gt; is dispatched from the &lt;code&gt;finally&lt;/code&gt; block in &lt;code&gt;Worker::process()&lt;/code&gt;, and a process killed with &lt;code&gt;SIGKILL&lt;/code&gt; never reaches a &lt;code&gt;finally&lt;/code&gt; block. No &lt;code&gt;JobAttempted&lt;/code&gt; means no duration, and no duration means no alert.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-slow-job-alerts" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What I'd register instead
&lt;/h2&gt;

&lt;p&gt;Keep the slow job alert, but don't make it your only timeout signal. This is the setup I'd put in &lt;code&gt;AppServiceProvider&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Carbon&lt;/span&gt;\&lt;span class="nc"&gt;CarbonInterval&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Queue&lt;/span&gt;\&lt;span class="nc"&gt;Events&lt;/span&gt;\&lt;span class="nc"&gt;JobTimedOut&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Queue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;boot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Jobs that finish, but slower than they should&lt;/span&gt;
    &lt;span class="nc"&gt;Queue&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;whenJobRunsLongerThan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CarbonInterval&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Slow job: {$job-&amp;gt;resolveName()} took {$duration}ms"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Jobs the worker had to kill&lt;/span&gt;
    &lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;JobTimedOut&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;JobTimedOut&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Job timed out: {$event-&amp;gt;job-&amp;gt;resolveName()} after {$event-&amp;gt;timeout}s"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pass a &lt;code&gt;CarbonInterval&lt;/code&gt;, never a plain number.&lt;/strong&gt; It means the same thing in both APIs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set the threshold well under your timeout.&lt;/strong&gt; The alert only sees jobs that finish, so it's an early warning. With the default &lt;code&gt;--timeout=60&lt;/code&gt;, a 30 second threshold tells you a job is drifting toward the limit while it still completes. The timeout itself has to stay below &lt;code&gt;retry_after&lt;/code&gt;, which &lt;a href="https://hafiz.dev/blog/laravel-queue-jobs-processing-10000-tasks-without-breaking" rel="noopener noreferrer"&gt;the 10,000 tasks post&lt;/a&gt; explains.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Listen for &lt;code&gt;JobTimedOut&lt;/code&gt; for the jobs that don't finish.&lt;/strong&gt; The worker dispatches it on every timeout, before the kill, whether or not the job has retries left. Keep the listener quick, though. It runs inside a process that's about to kill itself.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A timeout isn't the only way a worker dies before it can tidy up. A deploy sends &lt;code&gt;SIGTERM&lt;/code&gt; and then &lt;code&gt;SIGKILL&lt;/code&gt; after the grace period, which I walked through in &lt;a href="https://hafiz.dev/blog/laravel-queue-worker-sigterm-interruptible-jobs" rel="noopener noreferrer"&gt;the queue worker SIGTERM post&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background scheduled tasks are never measured
&lt;/h2&gt;

&lt;p&gt;The scheduler version listens for &lt;code&gt;ScheduledTaskFinished&lt;/code&gt; and &lt;code&gt;ScheduledTaskFailed&lt;/code&gt;. &lt;code&gt;schedule:run&lt;/code&gt; times each task by wrapping the call that starts it, and for a task with &lt;code&gt;runInBackground()&lt;/code&gt; that call returns as soon as the process is spawned. Two tasks, a 3 second one in the foreground and a 4 second one in the background:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ php artisan schedule:run
 2026-11-06 11:20:51 Running ['artisan' app:slow-task 3] .. 3s DONE
 2026-11-06 11:20:55 Running ['artisan' app:slow-task 4] in background  5.56ms DONE
$ grep WARNING storage/logs/laravel.log
[2026-11-06 11:20:55] local.WARNING: [schedule 2] '/opt/homebrew/Cellar/php@8.3/8.3.22/bin/php' 'artisan' app:slow-task 3 &amp;gt; '/dev/null' 2&amp;gt;&amp;amp;1 took 3.23s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The foreground task fired at 3.23s. The background one never did. The scheduler recorded the 5.56ms it took to start the process, not the four seconds the command ran, and nothing compares the real runtime later. If a long task has to run in the background, time it inside the command itself. (&lt;a href="https://laravel.com/docs/13.x/scheduling#background-tasks" rel="noopener noreferrer"&gt;Background tasks&lt;/a&gt; in the docs covers how they run.)&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Does whenJobRunsLongerThan fire while the job is still running?
&lt;/h3&gt;

&lt;p&gt;No. It listens for &lt;code&gt;JobAttempted&lt;/code&gt;, which the worker dispatches after an attempt ends. A job stuck at minute 20 of a 30 minute timeout produces nothing until it finishes.&lt;/p&gt;

&lt;h3&gt;
  
  
  What unit does the threshold use?
&lt;/h3&gt;

&lt;p&gt;Milliseconds for &lt;code&gt;Queue::whenJobRunsLongerThan()&lt;/code&gt; and seconds for &lt;code&gt;Schedule::whenTaskRunsLongerThan()&lt;/code&gt;. Both convert a &lt;code&gt;CarbonInterval&lt;/code&gt; correctly, so use one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does it alert on a job that hits the worker timeout?
&lt;/h3&gt;

&lt;p&gt;No. The worker kills its own process with &lt;code&gt;SIGKILL&lt;/code&gt; before &lt;code&gt;JobAttempted&lt;/code&gt; is dispatched. Listen for &lt;code&gt;JobTimedOut&lt;/code&gt; instead, which fires just before the kill. The &lt;a href="https://laravel.com/docs/13.x/queues#timeout" rel="noopener noreferrer"&gt;queue timeout docs&lt;/a&gt; cover how the timeout itself works.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does it work with Horizon?
&lt;/h3&gt;

&lt;p&gt;I didn't run Horizon for this test. Horizon's &lt;code&gt;horizon:work&lt;/code&gt; command extends Laravel's own &lt;code&gt;queue:work&lt;/code&gt; command (I checked in Horizon 5.50.1), so jobs go through the same &lt;code&gt;Worker&lt;/code&gt; class and the same timeout path. I'd expect the same results, but confirm on your setup. If you're still choosing between the two, &lt;a href="https://hafiz.dev/blog/laravel-cloud-managed-queues-vs-horizon" rel="noopener noreferrer"&gt;Horizon vs Cloud's managed queues&lt;/a&gt; covers the trade-offs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does it work with the sync driver?
&lt;/h3&gt;

&lt;p&gt;Yes. The sync queue dispatches &lt;code&gt;JobAttempted&lt;/code&gt; with a duration too, so a slow &lt;code&gt;dispatchSync()&lt;/code&gt; call triggers it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A slow alert needs a timeout listener next to it
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;whenJobRunsLongerThan&lt;/code&gt; is a good alert for jobs that finish slowly, and it costs one line. But it can't see the job that never finishes, and that's the one that hurts. And if you use the scheduler version, a task with &lt;code&gt;runInBackground()&lt;/code&gt; is invisible to it.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>queues</category>
      <category>laravel13</category>
      <category>monitoring</category>
    </item>
    <item>
      <title>Herd 2 Workspaces for Parallel Coding Agents: What Is Isolated and What Is Not</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Mon, 09 Nov 2026 05:15:08 +0000</pubDate>
      <link>https://dev.to/hafiz619/herd-2-workspaces-for-parallel-coding-agents-what-is-isolated-and-what-is-not-492j</link>
      <guid>https://dev.to/hafiz619/herd-2-workspaces-for-parallel-coding-agents-what-is-isolated-and-what-is-not-492j</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/herd-2-workspaces-parallel-coding-agents" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Herd 2 came out on 5 November, and its headline feature is workspaces: "isolated copies of a site that live on their own git branch and are served on their own domain." The pitch is parallel coding agents. Give each agent its own copy of the app and let them work without stepping on each other.&lt;/p&gt;

&lt;p&gt;I ran parallel Claude Code sessions on &lt;a href="https://hafiz.dev/blog/git-worktrees-for-laravel-developers-run-multiple-claude-code-sessions-in-parallel" rel="noopener noreferrer"&gt;git worktrees&lt;/a&gt; back in March, and the files were never the hard part. The hard part was everything the files point at. So I installed Herd 2.1.0 (Homebrew already ships 2.1), created a fresh Laravel 13.40 app, made five workspaces from it and tried to break them. Herd prints a database warning every time you create one, so I tested whether it holds. And the database wasn't the only thing two copies of the app ended up sharing. All output below is real.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a workspace actually is
&lt;/h2&gt;

&lt;p&gt;The app lives in &lt;code&gt;~/Herd/orders&lt;/code&gt;, so Herd serves it at &lt;code&gt;orders.test&lt;/code&gt;. One command creates a workspace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ herd workspace feature-a
✓ Creating Workspace
✓ Cloning Directory (this can take a moment)
✓ Linking Site
✓ Updating .env
✓ Finishing Up
Workspace [feature-a] is ready at [http://feature-a.orders.test].
 WARNING  The workspace shares the database of [orders] — migrations and destructive operations affect the parent site.
  Pass `--database=clone` for a copy of the parent database or `--database=empty` for a fresh one.
  cd "/Users/hafizzeeshanriaz/Library/Application Support/Herd/devtools/clones/8543c00e/feature-a-aa198b31"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It isn't a git worktree. Herd makes a copy-on-write clone of the whole folder (APFS clones files without duplicating the bytes until one side changes them), puts it in Herd's own application support folder, and gives it a full &lt;code&gt;.git&lt;/code&gt; directory on a new branch named after the workspace. The new site answers at &lt;code&gt;feature-a.orders.test&lt;/code&gt; straight away.&lt;/p&gt;

&lt;p&gt;The clone takes everything, untracked files included. So the workspace has its own &lt;code&gt;.env&lt;/code&gt; and its own &lt;code&gt;vendor/&lt;/code&gt;. Herd then rewrites the &lt;code&gt;.env&lt;/code&gt;, but only the keys that already exist. Here's the whole difference between the two files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ diff .env &amp;lt;workspace&amp;gt;/.env
5c5
&amp;lt; APP_URL=http://localhost:8000
---
&amp;gt; APP_URL=http://feature-a.orders.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One line. Herd's &lt;a href="https://herd.laravel.com/docs/macos/sites/workspaces" rel="noopener noreferrer"&gt;workspace docs&lt;/a&gt; say it also touches &lt;code&gt;SESSION_DOMAIN&lt;/code&gt;, &lt;code&gt;SANCTUM_STATEFUL_DOMAINS&lt;/code&gt; and &lt;code&gt;DB_DATABASE&lt;/code&gt; when those are set, and only &lt;code&gt;DB_DATABASE&lt;/code&gt; when the workspace gets its own database. A fresh Laravel app sets none of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The database warning, tested
&lt;/h2&gt;

&lt;p&gt;Every &lt;code&gt;herd workspace&lt;/code&gt; run ends with the same warning: the workspace shares the parent's database, so migrations and destructive operations affect the parent site. &lt;code&gt;herd workspaces&lt;/code&gt; agrees and lists &lt;code&gt;feature-a&lt;/code&gt; with a database of &lt;code&gt;shared&lt;/code&gt;. So I put one user in the parent and ran the most destructive command an agent is likely to run.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/herd-2-workspaces-parallel-coding-agents" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ php artisan tinker --execute="echo App\\Models\\User::count();"   # parent
1
$ cd &amp;lt;workspace&amp;gt; &amp;amp;&amp;amp; php artisan migrate:fresh --force
 Dropping all tables .. 4.81ms DONE
 INFO Preparing database.
 Creating migration table .. 2.00ms DONE
 INFO Running migrations.
 0001_01_01_000000_create_users_table .. 3.35ms DONE
 0001_01_01_000001_create_cache_table .. 1.65ms DONE
$ php artisan tinker --execute="echo App\\Models\\User::count();"   # parent again
1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The parent still has its user. Laravel's default SQLite connection doesn't set &lt;code&gt;DB_DATABASE&lt;/code&gt;, so each app reads &lt;code&gt;database/database.sqlite&lt;/code&gt; relative to its own folder, and the clone took its own copy of that file (different inode, same 98,304 bytes). Herd's warning describes the database Herd thinks it's sharing. The app was never sharing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  With an absolute database path
&lt;/h2&gt;

&lt;p&gt;That changes the moment &lt;code&gt;DB_DATABASE&lt;/code&gt; holds a value that means the same thing in both folders. An absolute SQLite path does. So does the database name of every MySQL or PostgreSQL app, and Herd copies the &lt;code&gt;.env&lt;/code&gt; as-is in shared mode. I added an absolute path to the parent's &lt;code&gt;.env&lt;/code&gt; and created a second workspace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB_CONNECTION=sqlite
DB_DATABASE=/Users/hafizzeeshanriaz/Herd/orders/database/database.sqlite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ php artisan tinker --execute="echo App\\Models\\User::count();"   # parent
1
$ cd &amp;lt;workspace feature-b&amp;gt; &amp;amp;&amp;amp; php artisan migrate:fresh --force
 Dropping all tables .. 3.29ms DONE
 INFO Preparing database.
 Creating migration table .. 2.10ms DONE
$ php artisan tinker --execute="echo App\\Models\\User::count();"   # parent again
0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gone. The workspace dropped every table in the parent's database. I only tested SQLite, because Herd's MySQL and PostgreSQL services need &lt;a href="https://herd.laravel.com/" rel="noopener noreferrer"&gt;Herd Pro&lt;/a&gt;, but the mechanism is the same &lt;code&gt;.env&lt;/code&gt; line. A &lt;code&gt;DB_DATABASE=orders&lt;/code&gt; on MySQL points both sites at the same &lt;code&gt;orders&lt;/code&gt; database.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--database=clone&lt;/code&gt; fixes it. Herd copies the database and points the workspace at the copy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ herd workspace feature-c --database=clone
✓ Creating Workspace
✓ Cloning Directory (this can take a moment)
✓ Linking Site
✓ Preparing Database
✓ Updating .env
✓ Finishing Up
Workspace [feature-c] is ready at [http://feature-c.orders.test].
The workspace uses its own SQLite database — a copy of the parent site's.
  cd "/Users/hafizzeeshanriaz/Library/Application Support/Herd/devtools/clones/8543c00e/feature-c-fe2986fe"
$ cd &amp;lt;workspace feature-c&amp;gt; &amp;amp;&amp;amp; php artisan migrate:fresh --force
 Dropping all tables .. 3.26ms DONE
$ php artisan tinker --execute="echo App\\Models\\User::count();"   # parent
1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The workspace's &lt;code&gt;.env&lt;/code&gt; now has &lt;code&gt;DB_DATABASE&lt;/code&gt; set to the copy inside the workspace folder, so &lt;code&gt;migrate:fresh&lt;/code&gt; wiped the copy and left the parent alone. There's also &lt;code&gt;--database=empty&lt;/code&gt;, which creates a fresh database and runs your migrations unless you pass &lt;code&gt;--no-migrate&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Herd Studio, the browser panel Herd 2 adds for running agents next to a site, shows the same list. The cloned workspace gets a DB copy badge. The others get nothing, &lt;code&gt;feature-a&lt;/code&gt; included, even though it was the one with its own database all along.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fozn4h1a0wavvh4twt4fu.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fozn4h1a0wavvh4twt4fu.webp" alt="Herd Studio's workspace switcher for orders.test, with only feature-c marked DB copy" width="799" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The queue goes wherever the database goes
&lt;/h2&gt;

&lt;p&gt;This is the one I didn't expect. A fresh Laravel app uses &lt;code&gt;QUEUE_CONNECTION=database&lt;/code&gt;, so a shared database also means a shared &lt;code&gt;jobs&lt;/code&gt; table. In a shared workspace, I did what an agent building a feature would do. I created a job class that only exists in the workspace and dispatched it. Then I ran the parent site's worker:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd &amp;lt;workspace feature-b&amp;gt; &amp;amp;&amp;amp; php artisan tinker --execute="App\\Jobs\\SendWeeklyReport::dispatch();"
$ cd ~/Herd/orders &amp;amp;&amp;amp; php artisan queue:work --once   # the parent site's worker
 2026-11-06 12:17:24 App\Jobs\SendWeeklyReport .. RUNNING
 2026-11-06 12:17:24 App\Jobs\SendWeeklyReport .. 2.44ms FAIL
$ php artisan queue:failed   # parent
 2026-11-06 12:17:24 01e3dde9-e667-4bd1-8971-f810f14bc45d database@default App\Jobs\SendWeeklyReport
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The parent's worker picked up the workspace's job and failed on it, because the class only exists in the workspace. The exception in the parent's &lt;code&gt;failed_jobs&lt;/code&gt; reads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ErrorException: Illuminate\Queue\CallQueuedHandler::commandShouldBeDebounced(): The script tried to access a property on an incomplete object. Please ensure tha
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's the same class of bug as &lt;a href="https://hafiz.dev/blog/multi-tenancy-queues-three-bugs-laravel-saas" rel="noopener noreferrer"&gt;a tenant's job running in the wrong tenant&lt;/a&gt;. The job is fine. It just ran in the wrong app. With two agents changing job payloads in parallel, the failures land in the parent's &lt;code&gt;failed_jobs&lt;/code&gt;, and the parent never dispatched any of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Unpushed commits are left out
&lt;/h2&gt;

&lt;p&gt;The last surprise isn't about the database. Herd's settings have &lt;code&gt;workspaceBaseFromOrigin&lt;/code&gt; turned on (Settings → Advanced in the app), so a workspace starts from the last pushed state of your branch. I pushed &lt;code&gt;main&lt;/code&gt;, committed an &lt;code&gt;Invoice&lt;/code&gt; model without pushing, then created two workspaces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git log --oneline -2
97a52bc Add Invoice model (not pushed)
c8084d6 Fresh Laravel app
$ git status -sb | head -1
## main...origin/main [ahead 1]
$ herd workspace feature-d
Workspace [feature-d] is ready at [http://feature-d.orders.test].
 WARNING  The workspace shares the database of [orders] — migrations and destructive operations affect the parent site.
 WARNING  The workspace starts from the last pushed state of [main] — your 1 unpushed commit(s) are not included. Push first or re-create it with `herd workspace --local` if you need them.
$ cd &amp;lt;workspace feature-d&amp;gt; &amp;amp;&amp;amp; git log --oneline -2 &amp;amp;&amp;amp; ls app/Models
c8084d6 Fresh Laravel app
User.php
$ herd workspace feature-e --local
Workspace [feature-e] is ready at [http://feature-e.orders.test].
$ cd &amp;lt;workspace feature-e&amp;gt; &amp;amp;&amp;amp; ls app/Models
Invoice.php
User.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Herd does warn about it, and &lt;code&gt;--local&lt;/code&gt; includes the unpushed commit. But an agent handed a workspace without that flag starts from code that's missing your latest commit, and nothing in the workspace itself tells it so.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I'd set it up for agents
&lt;/h2&gt;

&lt;p&gt;Four of the six results come down to one line in &lt;code&gt;.env&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/herd-2-workspaces-parallel-coding-agents" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create every agent workspace with &lt;code&gt;--database=clone&lt;/code&gt;.&lt;/strong&gt; It isolated the database in the setup where shared mode wiped the parent, and the queue follows, since the &lt;code&gt;jobs&lt;/code&gt; table lives in that database. &lt;code&gt;--database=empty&lt;/code&gt; gives a fresh one instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't read the warning as the answer.&lt;/strong&gt; It said "shared" for a workspace that wasn't, and it would say the same for one that was. Check &lt;code&gt;DB_DATABASE&lt;/code&gt; in the workspace's &lt;code&gt;.env&lt;/code&gt; instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Push first, or pass &lt;code&gt;--local&lt;/code&gt;.&lt;/strong&gt; Otherwise the agent works on your last pushed commit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delete workspaces when the agent is done.&lt;/strong&gt; &lt;code&gt;herd workspace:delete&lt;/code&gt; drops a workspace's own database unless you pass &lt;code&gt;--keep-database&lt;/code&gt;. Deleting a shared workspace left the parent's database alone in my test, and Herd kept the branch in the parent repository.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you start agents from Herd Studio instead of the CLI, the choice moves into a menu under the prompt box. A new workspace there takes its database mode from Herd's settings, under Workspaces, so check that setting before you start an agent there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fakm7n7iuznfd0ws6bmc0.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fakm7n7iuznfd0ws6bmc0.webp" alt="The Herd Studio menu for where a prompt runs, with New workspace taking its database from Settings" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One caveat for my own setup. Herd only runs on macOS and Windows, and its FAQ says Linux isn't ready yet. I moved my day-to-day development to a &lt;a href="https://hafiz.dev/blog/cloud-only-laravel-development-7-weeks-dev-box" rel="noopener noreferrer"&gt;remote dev box&lt;/a&gt; at the end of August, so workspaces only help me when I'm working on the Mac.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Are Herd 2 workspaces git worktrees?
&lt;/h3&gt;

&lt;p&gt;Not by default. &lt;code&gt;herd workspace&lt;/code&gt; makes a copy-on-write clone of the folder with a full &lt;code&gt;.git&lt;/code&gt; directory on a new branch. Herd can also serve a worktree you created yourself with &lt;code&gt;git worktree add&lt;/code&gt;, and &lt;code&gt;herd workspaces&lt;/code&gt; lists those as worktrees that aren't served yet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do Herd 2 workspaces need Herd Pro?
&lt;/h3&gt;

&lt;p&gt;Not for what I tested. Workspaces, &lt;code&gt;--database=clone&lt;/code&gt; and the delete command all worked on the free version of Herd 2.1.0 with SQLite. The MySQL and PostgreSQL services themselves are part of Herd Pro.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does each workspace get its own database?
&lt;/h3&gt;

&lt;p&gt;Only with &lt;code&gt;--database=clone&lt;/code&gt; or &lt;code&gt;--database=empty&lt;/code&gt;. The default is &lt;code&gt;shared&lt;/code&gt;, which shares whatever &lt;code&gt;DB_DATABASE&lt;/code&gt; points at. For Laravel's default SQLite file inside the project, that happens to be a separate copy anyway.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does deleting a workspace delete my database?
&lt;/h3&gt;

&lt;p&gt;A workspace with its own database has that database dropped unless you pass &lt;code&gt;--keep-database&lt;/code&gt;. Deleting a shared workspace didn't touch the parent's database in my test.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can two agents run migrations at the same time?
&lt;/h3&gt;

&lt;p&gt;Yes, if each workspace has its own database. In shared mode they both migrate the parent's database, and the second &lt;code&gt;migrate:fresh&lt;/code&gt; wipes whatever the first one just built.&lt;/p&gt;

&lt;h2&gt;
  
  
  Isolated files, shared state
&lt;/h2&gt;

&lt;p&gt;Workspaces isolate the code well. Every workspace got its own files, branch and domain, with no setup. The database and the queue are only as isolated as &lt;code&gt;DB_DATABASE&lt;/code&gt; makes them, and Herd's warning can't tell you which case you're in.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>laravelherd</category>
      <category>aiagents</category>
      <category>localdevelopment</category>
    </item>
    <item>
      <title>One Request Waited 5 Seconds to Clean Up Laravel Sessions. Here Is What 13.39's session:garbage-collect Changes</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Thu, 05 Nov 2026 05:15:09 +0000</pubDate>
      <link>https://dev.to/hafiz619/one-request-waited-5-seconds-to-clean-up-laravel-sessions-here-is-what-1339s-5c0g</link>
      <guid>https://dev.to/hafiz619/one-request-waited-5-seconds-to-clean-up-laravel-sessions-here-is-what-1339s-5c0g</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/laravel-session-garbage-collection-lottery" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;I put a million expired sessions into the &lt;code&gt;sessions&lt;/code&gt; table of a fresh Laravel 13.39 app and set the session lottery to always win. The next page view took 5.2 seconds. Every other page view took 6 milliseconds.&lt;/p&gt;

&lt;p&gt;That's the lottery. By default, about 2 in every 100 requests that start a session also clean up expired sessions, and they do it before your route runs. Laravel 13.39 added &lt;a href="https://github.com/laravel/framework/pull/62104" rel="noopener noreferrer"&gt;&lt;code&gt;session:garbage-collect&lt;/code&gt;&lt;/a&gt; so a scheduled job can do that work instead. I measured both on the default setup, the &lt;code&gt;database&lt;/code&gt; session driver on SQLite. The command fixed the unlucky-visitor problem and created a new one. All output below is real.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the lottery works
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;StartSession&lt;/code&gt; middleware starts the session, then rolls the dice, then calls your route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setLaravelSession&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;startSession&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;collectGarbage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$session&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;collectGarbage()&lt;/code&gt; checks the &lt;code&gt;lottery&lt;/code&gt; value in &lt;code&gt;config/session.php&lt;/code&gt;, which ships as &lt;code&gt;[2, 100]&lt;/code&gt;. On a win, the database handler runs one query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getQuery&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'last_activity'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;='&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;currentTime&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;$lifetime&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The skeleton's migration indexes &lt;code&gt;last_activity&lt;/code&gt;, so finding the expired rows is cheap. Deleting them is not, once there are enough of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where a million expired sessions come from
&lt;/h2&gt;

&lt;p&gt;Any request to a &lt;code&gt;web&lt;/code&gt; route without a session cookie gets a new session, and the database driver writes it as a row. I sent 50 requests with plain &lt;code&gt;curl&lt;/code&gt;, then 50 more that kept their cookies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rows before: 0
after 50 requests without cookies: 50
after 50 more with one cookie jar: 51
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Crawlers, uptime monitors and most scripts don't keep cookies. Each hit is a row that sits there until it expires and something deletes it. With steady traffic and the lottery on, cleanup runs often enough that each win only has a few rows to delete. A backlog builds when cleanup stops, for example when the lottery is set to &lt;code&gt;[0, 100]&lt;/code&gt; with nothing scheduled in its place, or on an old table that was never cleaned.&lt;/p&gt;

&lt;p&gt;I seeded a backlog directly in SQLite, with rows shaped like real ones (same payload size, a crawler user agent, &lt;code&gt;last_activity&lt;/code&gt; three days back):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;seeded in 2.4s
1000051|1000000
db size: 404M
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's 1,000,000 expired rows and 51 live ones, in a 404 MB database file.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the winning request pays
&lt;/h2&gt;

&lt;p&gt;With the lottery off, page views took 6 to 10 milliseconds. Then I set it to &lt;code&gt;[100, 100]&lt;/code&gt;, so the next request would win:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lottery [0,100], 5 requests: 0.010s 0.006s 0.006s 0.006s 0.006s
lottery [100,100], request that runs the cleanup: 5.199s
rows after: 57
next requests (nothing left to delete): 0.007s 0.006s 0.006s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I reseeded and ran the winning request twice more, at 6.26 and 5.40 seconds. Then I tried smaller backlogs, each seeded fresh:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Expired rows&lt;/th&gt;
&lt;th&gt;Lottery-winning request&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1,000&lt;/td&gt;
&lt;td&gt;8 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10,000&lt;/td&gt;
&lt;td&gt;27 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100,000&lt;/td&gt;
&lt;td&gt;223 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1,000,000&lt;/td&gt;
&lt;td&gt;5.2 to 6.3 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Up to a few thousand rows, nobody notices. At a million, one visitor stares at a blank page for five seconds and never knows why. If you've seen a random slow request in your logs that you couldn't reproduce, a lottery win is a candidate.&lt;/p&gt;

&lt;h2&gt;
  
  
  What session:garbage-collect changes
&lt;/h2&gt;

&lt;p&gt;The new command runs the same handler method on your schedule instead of inside a request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// routes/console.php&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Support\Facades\Schedule&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Schedule&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'session:garbage-collect'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hourly&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then turn the lottery off in &lt;code&gt;config/session.php&lt;/code&gt;, so requests stop doing it as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="s1"&gt;'lottery'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the same million-row backlog, the command did the work in about the same time, with no visitor attached to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;php artisan session:garbage-collect
&lt;span class="go"&gt; INFO Session garbage collector ran successfully.
real 5.84
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It doesn't report how many rows it deleted. Count the table before and after if you want to know.&lt;/p&gt;

&lt;h2&gt;
  
  
  On SQLite, the scheduler doesn't save your visitors
&lt;/h2&gt;

&lt;p&gt;I ran the command again on the full backlog and sent a request every 200 milliseconds while it worked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;request 1: 200 0.009059s
request 2: 200 5.231497s
request 3: 200 5.032121s
request 4: 200 4.831341s
request 5: 200 4.627754s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Request 1 got in before the delete started. The other four waited for it to finish. Every web request writes its session at the end, and SQLite allows one writer at a time, so a five-second DELETE holds up every page view that arrives during it. Moving the cleanup to the scheduler turned one unlucky visitor into everyone who showed up in those five seconds.&lt;/p&gt;

&lt;p&gt;That only bites with a big backlog. Run the command often enough that each run deletes a few thousand rows, and each one takes milliseconds, as the table above shows. The problem is the first run on a table that already has a backlog.&lt;/p&gt;

&lt;p&gt;I only measured SQLite here, which is what a new Laravel app uses out of the box. MySQL and PostgreSQL don't lock the whole database for a delete, so check your own driver before assuming either result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clear an existing backlog in chunks
&lt;/h2&gt;

&lt;p&gt;For the first cleanup, delete in batches and pause between them, so other writes get a turn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// routes/console.php&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="no"&gt;Illuminate\Support\Facades\DB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Artisan&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'sessions:prune-chunked {--chunk=5000}'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$cutoff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;subMinutes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'session.lifetime'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getTimestamp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$deleted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$batch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'sessions'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'last_activity'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;='&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$cutoff&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;option&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'chunk'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="nv"&gt;$deleted&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nv"&gt;$batch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nb"&gt;usleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50_000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$batch&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Deleted &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$deleted&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; expired sessions."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same million rows, same requests arriving every half second while it ran:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;request 1: 200 0.017038s
request 2: 200 0.028787s
request 3: 200 0.027196s
request 4: 200 0.026492s
request 5: 200 0.029231s
request 6: 200 0.030707s
request 7: 200 0.028865s
request 8: 200 0.027779s
Deleted 1000000 expired sessions.
real 17.41
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It took 17 seconds instead of 6, and no request went over 31 milliseconds.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/laravel-session-garbage-collection-lottery" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Run it once, then let &lt;code&gt;session:garbage-collect&lt;/code&gt; keep the table small from then on. If chunked deletes are new to you, the same idea shows up in &lt;a href="https://hafiz.dev/blog/laravel-query-optimization-from-3-seconds-to-30ms" rel="noopener noreferrer"&gt;my query optimization post&lt;/a&gt;, and &lt;a href="https://hafiz.dev/blog/database-indexing-in-laravel-boost-mysql-performance-with-smart-indexes" rel="noopener noreferrer"&gt;the indexing guide&lt;/a&gt; covers why the &lt;code&gt;last_activity&lt;/code&gt; index matters for the &lt;code&gt;where&lt;/code&gt; half of it. &lt;a href="https://hafiz.dev/blog/eloquent-patterns-silently-break-mysql-index" rel="noopener noreferrer"&gt;Six Eloquent patterns that quietly skip an index&lt;/a&gt; shows how that half can go wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The file driver pays even when nothing has expired
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;file&lt;/code&gt; driver cleans up with Symfony Finder. It walks every file in &lt;code&gt;storage/framework/sessions&lt;/code&gt; and checks each modification time. I created 100,000 session files and ran the command twice, first with all of them fresh, then with all of them three days old:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;SESSION_DRIVER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;file php artisan session:garbage-collect   &lt;span class="c"&gt;# 100,000 fresh files&lt;/span&gt;
&lt;span class="go"&gt;real 0.98
files left: 100000

&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;SESSION_DRIVER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;file php artisan session:garbage-collect   &lt;span class="c"&gt;# 100,000 expired files&lt;/span&gt;
&lt;span class="go"&gt;real 12.67
files left: 0
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Almost a second to delete nothing. On the file driver, every lottery win pays for that scan, however few sessions have actually expired. Twelve seconds to delete them all. That's the strongest case for the new command on the file driver, because the scan cost never goes away.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd set up
&lt;/h2&gt;

&lt;p&gt;For the &lt;code&gt;database&lt;/code&gt; and &lt;code&gt;file&lt;/code&gt; drivers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// config/session.php&lt;/span&gt;
&lt;span class="s1"&gt;'lottery'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// routes/console.php&lt;/span&gt;
&lt;span class="nc"&gt;Schedule&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'session:garbage-collect'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;everyFifteenMinutes&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every fifteen minutes keeps each run small on a busy site. If you run several servers against one database, add &lt;code&gt;-&amp;gt;onOneServer()&lt;/code&gt;, which needs a cache store that supports atomic locks. With the file driver, each server has its own sessions folder, so the command runs on each one. If the table already has a backlog, run the chunked version once first.&lt;/p&gt;

&lt;p&gt;Or skip the question. The cache-backed drivers, Redis among them, write each session with a TTL, and their &lt;code&gt;gc()&lt;/code&gt; method returns 0. Expired sessions disappear on their own. If you already run Redis for queues or cache, it's a one-line &lt;code&gt;.env&lt;/code&gt; change.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What does Laravel's session lottery do?
&lt;/h3&gt;

&lt;p&gt;On each request that starts a session, Laravel rolls the &lt;code&gt;lottery&lt;/code&gt; odds from &lt;code&gt;config/session.php&lt;/code&gt;, &lt;code&gt;[2, 100]&lt;/code&gt; by default. On a win, it deletes expired sessions before your route runs, so that request waits for the delete.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I turn off the session lottery?
&lt;/h3&gt;

&lt;p&gt;Set &lt;code&gt;'lottery' =&amp;gt; [0, 100]&lt;/code&gt; in &lt;code&gt;config/session.php&lt;/code&gt;. Then schedule &lt;code&gt;session:garbage-collect&lt;/code&gt;, which Laravel 13.39 added, or expired sessions will pile up forever with the &lt;code&gt;database&lt;/code&gt; and &lt;code&gt;file&lt;/code&gt; drivers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does session:garbage-collect work with Redis sessions?
&lt;/h3&gt;

&lt;p&gt;It runs, but it has nothing to do. The cache-backed handlers store sessions with a TTL, so they expire on their own, and their &lt;code&gt;gc()&lt;/code&gt; method returns 0.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why is my sessions table so big?
&lt;/h3&gt;

&lt;p&gt;Every request without a session cookie creates a new row, and crawlers, uptime checks and scripts rarely send cookies. Rows stay until cleanup deletes them, so if the lottery is off and nothing is scheduled, the table only grows.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is the first run of session:garbage-collect safe on a big table?
&lt;/h3&gt;

&lt;p&gt;On SQLite with a big backlog, not during traffic. A single delete of a million rows held up every request for about five seconds in my test. Clear the backlog in chunks first, then let the scheduled command keep up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;On SQLite, moving the cleanup to the scheduler is only half the fix. Check how many expired rows you have before the first scheduled run. If the answer is in the hundreds of thousands, clear them in chunks once, then let a small, frequent &lt;code&gt;session:garbage-collect&lt;/code&gt; keep it from happening again.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>sessions</category>
      <category>database</category>
      <category>performance</category>
    </item>
    <item>
      <title>Composer 2.11's Cooldown in a Laravel App: Safer Updates, Except When the Update Is the Security Fix</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Mon, 02 Nov 2026 05:15:09 +0000</pubDate>
      <link>https://dev.to/hafiz619/composer-211s-cooldown-in-a-laravel-app-safer-updates-except-when-the-update-is-the-security-fix-24e6</link>
      <guid>https://dev.to/hafiz619/composer-211s-cooldown-in-a-laravel-app-safer-updates-except-when-the-update-is-the-security-fix-24e6</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/composer-2-11-cooldown-laravel" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;On 31 October I turned on Composer 2.11's new cooldown in a Laravel 13 project, set it to seven days, and ran &lt;code&gt;composer update&lt;/code&gt;. It failed. Three days earlier Symfony had shipped a fix for CVE-2026-45070 in &lt;code&gt;symfony/mime&lt;/code&gt;. The cooldown was holding the fix back, and Composer's advisory policy was blocking every older version. My project had nothing it was allowed to install.&lt;/p&gt;

&lt;p&gt;The release notes do say the cooldown applies to security fixes too. What they can't show is how fast that bites. The cooldown gives malware scanners time to flag a malicious version before &lt;code&gt;composer update&lt;/code&gt; ever offers it to you. But the same rule applies to the version that fixes your vulnerability.&lt;/p&gt;

&lt;p&gt;I tried it on a clean Laravel project with Composer 2.11.1, with &lt;code&gt;laravel/framework&lt;/code&gt; locked at 13.37.0. Here's what it changed, where it broke, and the setup I'd use. All output below is real.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the cooldown does
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://blog.packagist.com/composer-2-11-release/" rel="noopener noreferrer"&gt;Composer 2.11.0&lt;/a&gt; shipped on 29 October, and 2.11.1 followed a day later. The cooldown is part of the &lt;a href="https://getcomposer.org/doc/06-config.md#cooldown" rel="noopener noreferrer"&gt;&lt;code&gt;policy&lt;/code&gt; config&lt;/a&gt;. It's off by default, and it takes effect once you set a period:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer config policy.cooldown.period &lt;span class="s2"&gt;"7 days"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"config"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"policy"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"cooldown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"period"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"7 days"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The period takes values like &lt;code&gt;"6 hours"&lt;/code&gt;, &lt;code&gt;"1 day"&lt;/code&gt; or &lt;code&gt;"1 week"&lt;/code&gt;, measured from the publish time the repository reports for each version. It applies when Composer resolves dependencies, so &lt;code&gt;update&lt;/code&gt;, &lt;code&gt;require&lt;/code&gt; and &lt;code&gt;create-project&lt;/code&gt;. &lt;code&gt;composer install&lt;/code&gt; still installs exactly what's in &lt;code&gt;composer.lock&lt;/code&gt;. Dev versions like &lt;code&gt;dev-main&lt;/code&gt; are never withheld.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it did to a Laravel 13 project
&lt;/h2&gt;

&lt;p&gt;13.39.0 came out on 27 October, four days before I ran this. With a seven-day period, updating the framework stopped one release short:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ composer update laravel/framework
Loading composer repositories with package information
31 package version(s) withheld by the cooldown policy (run with -vv to list them).
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
  - Upgrading laravel/framework (v13.37.0 =&amp;gt; v13.38.0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;31 versions for one package, because the list also counts the &lt;code&gt;illuminate/*&lt;/code&gt; packages Laravel publishes alongside each release, a few seconds apart. &lt;code&gt;-vv&lt;/code&gt; lists them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;31 package version(s) withheld by the cooldown policy:
  - laravel/framework (v13.39.0) published 2026-10-27T14:05:37+00:00, available in 3 days 4 hours
  - illuminate/bus (v13.39.0) published 2026-10-27T14:04:59+00:00, available in 3 days 4 hours
  - illuminate/bus (v12.70.2) published 2026-10-27T14:08:11+00:00, available in 3 days 4 hours
  - illuminate/collections (v13.39.0) published 2026-10-27T14:05:01+00:00, available in 3 days 4 hours
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;composer outdated&lt;/code&gt; has a new marker for it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ composer outdated --direct
Legend:
! patch or minor release available - update recommended
~ major release available - update possible
c newer release still in the cooldown period - not installable yet
laravel/framework 13.38.0 c 13.39.0 (3d 4h left) The Laravel Framework.
phpunit/phpunit   12.5.42 c 13.4.4 (2d 17h left) The PHP Unit Testing framew...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And &lt;code&gt;--no-cooldown&lt;/code&gt; skips it for one package, one command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;composer update &lt;span class="nt"&gt;--no-cooldown&lt;/span&gt; laravel/framework
  - Upgrading laravel/framework &lt;span class="o"&gt;(&lt;/span&gt;v13.38.0 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; v13.39.0&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far it does what it says. The surprises started with a full update.&lt;/p&gt;

&lt;h2&gt;
  
  
  A full update downgraded 23 packages
&lt;/h2&gt;

&lt;p&gt;With &lt;code&gt;laravel/framework&lt;/code&gt; now at 13.39.0, still inside the cooldown, I ran a plain &lt;code&gt;composer update&lt;/code&gt;. I'll get to why it failed in the next section. With the package behind that failure exempted, here is what the same update planned:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ composer update --dry-run
78 package version(s) withheld by the cooldown policy (run with -vv to list them).
Updating dependencies
Lock file operations: 0 installs, 23 updates, 0 removals
  - Downgrading doctrine/inflector (2.1.1 =&amp;gt; 2.1.0)
  - Downgrading guzzlehttp/guzzle (8.3.1 =&amp;gt; 8.3.0)
  - Downgrading laravel/framework (v13.39.0 =&amp;gt; v13.38.0)
  - Downgrading league/commonmark (2.10.6 =&amp;gt; 2.10.4)
  - Downgrading nesbot/carbon (3.15.1 =&amp;gt; 3.15.0)
  - Downgrading symfony/console (v7.4.22 =&amp;gt; v7.4.21)
  - Downgrading symfony/http-kernel (v7.4.22 =&amp;gt; v7.4.21)
  - Downgrading symfony/mailer (v7.4.22 =&amp;gt; v7.4.19)
  ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Packagist announcement warns about this. A full &lt;code&gt;composer update&lt;/code&gt; re-checks every package, and anything locked at a version still inside the window gets swapped for an older one. A partial update leaves unrelated packages alone. If you add a cooldown to a project that's already up to date, your first full update moves it backwards. Run it with &lt;code&gt;--dry-run&lt;/code&gt; first and read the list.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the update is the security fix
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://symfony.com/cve-2026-45070" rel="noopener noreferrer"&gt;CVE-2026-45070&lt;/a&gt; is an email header injection in &lt;code&gt;symfony/mime&lt;/code&gt;, rated medium. The advisory was published on 28 October, alongside the fixed releases, 7.4.22 and 8.1.10. &lt;code&gt;laravel/framework&lt;/code&gt; requires &lt;code&gt;symfony/mime&lt;/code&gt;, so every Laravel app has it.&lt;/p&gt;

&lt;p&gt;Composer also blocks versions with known advisories during &lt;code&gt;update&lt;/code&gt; by default (&lt;code&gt;policy.advisories.block&lt;/code&gt; defaults to &lt;code&gt;true&lt;/code&gt;). Put the two policies together and a project still on the vulnerable 7.4.19 has nowhere to go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ composer update symfony/mime
2 package version(s) withheld by the cooldown policy (run with -vv to list them).
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - laravel/framework v13.39.0 requires symfony/mime ^7.4.0 || ^8.0.0 -&amp;gt; found symfony/mime[v7.4.0, ..., v7.4.22, v8.0.0, ..., v8.1.10] but these were not loaded, because:
      - v7.4.12, v7.4.13, v7.4.15, v7.4.16, v7.4.17, v7.4.18, v7.4.19, v8.0.12, v8.0.13, v8.0.15, v8.1.0, v8.1.2, v8.1.4, v8.1.5, v8.1.6, v8.1.7: affected by security advisories ("PKSA-wtxr-p26d-nn42")
      - v7.4.22, v8.1.10: still in the cooldown period configured in "policy.cooldown" (available in 4 days 9 hours)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Composer refuses to move you to a version it knows is vulnerable, and it refuses to move you to the fix because it's too new. So you stay on the version you're on, which is also vulnerable. And nothing at deploy time tells you. &lt;code&gt;composer install&lt;/code&gt; installed 7.4.19 from the lock file without a word and exited 0.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer audit&lt;/code&gt; is the one that speaks up. It found the advisory and exited 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ composer audit
Found 1 security vulnerability advisory affecting 1 package:
+-------------------+----------------------------------------------------------------------------------+
| Package           | symfony/mime                                                                     |
| Severity          | medium                                                                           |
| Advisory ID       | PKSA-wtxr-p26d-nn42                                                              |
| CVE               | CVE-2026-45070                                                                   |
| Title             | CVE-2026-45070: Email Header Injection via Non-Token Characters in Mime          |
|                   | Parameter Names                                                                  |
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The way out is one targeted command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ composer update symfony/mime --no-cooldown
  - Upgrading symfony/mime (v7.4.19 =&amp;gt; v7.4.22)
No security vulnerability advisories found.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use &lt;code&gt;--no-cooldown&lt;/code&gt; here, not &lt;code&gt;--no-blocking&lt;/code&gt;. Composer 2.11 has both, and the help text explains the difference. &lt;code&gt;--no-blocking&lt;/code&gt; "disables all policy blocking during this command", which includes the advisory and malware checks you want to keep. &lt;code&gt;--no-cooldown&lt;/code&gt; turns off the cooldown only, and the other policies still apply.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://hafiz.dev/blog/composer-2-11-cooldown-laravel" rel="noopener noreferrer"&gt;View the interactive component on hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;New projects fail the same way. With a seven-day period set through the environment, a fresh install broke that morning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ COMPOSER_POLICY_COOLDOWN_PERIOD="7 days" composer create-project laravel/laravel fresh-under-cooldown
Installing laravel/laravel (v13.11.0)
81 package version(s) withheld by the cooldown policy (run with -vv to list them).
Your requirements could not be resolved to an installable set of packages.
      - v7.4.22: still in the cooldown period configured in "policy.cooldown" (available in 4 days 8 hours)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;laravel new&lt;/code&gt; runs &lt;code&gt;composer create-project&lt;/code&gt; under the hood, so a cooldown in your global Composer config affects it too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your own packages
&lt;/h2&gt;

&lt;p&gt;Two kinds of repository came up in my test, and they behaved differently.&lt;/p&gt;

&lt;p&gt;A path repository, the usual setup for a package that lives in your monorepo, installed fine. Composer warned that it couldn't verify the publish date and moved on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The publication date of 1 package version(s) from path repo (packages/acme-helpers) could not be verified, the cooldown policy relied on the time field set by the package authors (run with -vv to list them).
  - Installing acme/helpers (1.0.0): Symlinking from packages/acme-helpers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A git repository with a tag I'd created a minute earlier did not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Problem 1
  - Root composer.json requires acme/sdk ^1.0, found acme/sdk[v1.0.0] but these were not loaded, because they are still in the cooldown period configured in "policy.cooldown" (available in 6 days 23 hours, based on the package-supplied time field as the repository provides no published-time).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the in-house SDK your team tagged this morning, blocked for a week. The &lt;code&gt;ignore&lt;/code&gt; list fixes it, with a reason that ends up in &lt;code&gt;composer.json&lt;/code&gt; for the next person:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"cooldown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"period"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"7 days"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"ignore"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"acme/*"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Our own packages, tagged by us"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that in place, the same &lt;code&gt;composer require acme/sdk&lt;/code&gt; locked v1.0.0 straight away. If you serve private packages from your own Composer repository, check what it reports. The Composer docs say a repository that doesn't provide &lt;code&gt;published-time&lt;/code&gt; makes the command error out while a cooldown is set, and a trusted repository can opt back into the older &lt;code&gt;time&lt;/code&gt; field with &lt;code&gt;require-published-time&lt;/code&gt; set to &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which period to pick
&lt;/h2&gt;

&lt;p&gt;The Packagist announcement suggests a few hours to a day. I ran the same full-update dry run with four periods, at 09:21 UTC on 31 October:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Period&lt;/th&gt;
&lt;th&gt;Versions withheld&lt;/th&gt;
&lt;th&gt;Full &lt;code&gt;composer update&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1 hour&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Resolves&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1 day&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Resolves (one bugfix release of &lt;code&gt;league/commonmark&lt;/code&gt; rolled back)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3 days&lt;/td&gt;
&lt;td&gt;41&lt;/td&gt;
&lt;td&gt;Fails on &lt;code&gt;symfony/mime&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7 days&lt;/td&gt;
&lt;td&gt;81&lt;/td&gt;
&lt;td&gt;Fails on &lt;code&gt;symfony/mime&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A day matches Packagist's own suggestion, and a security fix stops blocking you by the next working day. With three days, my full update stayed broken until the evening of 31 October. With seven, it stays broken until 4 November, all because one package every Laravel app depends on shipped a security fix.&lt;/p&gt;

&lt;p&gt;In CI you don't have to commit the setting. &lt;code&gt;COMPOSER_POLICY_COOLDOWN_PERIOD&lt;/code&gt; sets it from the environment. With nothing in &lt;code&gt;composer.json&lt;/code&gt;, this was enough for &lt;code&gt;outdated&lt;/code&gt; to apply it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ COMPOSER_POLICY_COOLDOWN_PERIOD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"7 days"&lt;/span&gt; composer outdated &lt;span class="nt"&gt;--direct&lt;/span&gt;
Cannot use laravel/framework&lt;span class="s1"&gt;'s latest version v13.39.0 as it is still in the cooldown period configured in "policy.cooldown" (available in 3 days 4 hours).
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The setup I'd use
&lt;/h2&gt;

&lt;p&gt;A one-day period, with your own vendor name exempt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"config"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"policy"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"cooldown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"period"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1 day"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"ignore"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"acme/*"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Our own packages, tagged by us"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add &lt;code&gt;composer audit&lt;/code&gt; to CI as its own step, because &lt;code&gt;composer install&lt;/code&gt; won't tell you about a vulnerable lock file and &lt;code&gt;audit&lt;/code&gt; exits 1 when it finds one. If you don't have a pipeline yet, &lt;a href="https://hafiz.dev/blog/laravel-cicd-github-actions-complete-guide" rel="noopener noreferrer"&gt;my GitHub Actions guide&lt;/a&gt; has a starting point. And write the escape hatch down before you need it. When &lt;code&gt;audit&lt;/code&gt; fails and the fix is still in cooldown, run &lt;code&gt;composer update vendor/package --no-cooldown&lt;/code&gt; for that one package.&lt;/p&gt;

&lt;p&gt;The cooldown and the audit cover different risks. The cooldown keeps a brand new malicious version out of your lock file. The audit catches a known vulnerability already in it. I wrote about the first problem after &lt;a href="https://hafiz.dev/blog/fake-laravel-packages-targeting-your-env-how-to-audit-composer-dependencies" rel="noopener noreferrer"&gt;fake Laravel packages started targeting .env files&lt;/a&gt;. A cooldown only helps if the fake is caught inside the window, so it doesn't replace reading what you install.&lt;/p&gt;

&lt;p&gt;If you're mid-upgrade, the cooldown adds one more kind of line to your conflict output. &lt;a href="https://hafiz.dev/blog/4-composer-conflicts-blocking-laravel-13-upgrade" rel="noopener noreferrer"&gt;The usual Laravel 13 upgrade conflicts&lt;/a&gt; still come first, and a release you're waiting for may now also be "still in the cooldown period".&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Does the Composer cooldown affect composer install?
&lt;/h3&gt;

&lt;p&gt;No. &lt;code&gt;composer install&lt;/code&gt; installs exactly what's in &lt;code&gt;composer.lock&lt;/code&gt;, whatever the cooldown says. The cooldown applies when Composer resolves versions, during &lt;code&gt;update&lt;/code&gt;, &lt;code&gt;require&lt;/code&gt; and &lt;code&gt;create-project&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does the cooldown hold back security fixes?
&lt;/h3&gt;

&lt;p&gt;Yes. Composer doesn't exempt them. The Packagist announcement explains why. Any rule that exempted releases based on advisory data would give attackers a way around the cooldown. Run &lt;code&gt;composer update vendor/package --no-cooldown&lt;/code&gt; when you need a fix sooner.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's the difference between --no-cooldown and --no-blocking?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;--no-cooldown&lt;/code&gt; turns off the cooldown for one command and keeps the advisory and malware policies active. &lt;code&gt;--no-blocking&lt;/code&gt; turns off all policy blocking, including those. For a security fix, &lt;code&gt;--no-cooldown&lt;/code&gt; is the one you want.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does composer update downgrade packages after I enable a cooldown?
&lt;/h3&gt;

&lt;p&gt;A full &lt;code&gt;composer update&lt;/code&gt; re-evaluates every package against the cooldown. A version you already have locked that is still inside the window gets replaced with the newest version outside it. A partial update, like &lt;code&gt;composer update vendor/package&lt;/code&gt;, leaves other packages alone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do my production servers need Composer 2.11?
&lt;/h3&gt;

&lt;p&gt;Not for the cooldown. It only matters where you run &lt;code&gt;update&lt;/code&gt; or &lt;code&gt;require&lt;/code&gt;, which is usually your machine or CI. Deploys that run &lt;code&gt;composer install&lt;/code&gt; from the lock file aren't affected. Upgrade anyway, though, because 2.11 also ships security fixes of its own, listed in the release notes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Set the cooldown to a day, exempt your own packages, and run &lt;code&gt;composer audit&lt;/code&gt; in CI. Then keep &lt;code&gt;composer update vendor/package --no-cooldown&lt;/code&gt; somewhere your team will find it. In the week I tried it, the cooldown's first real cost was a security fix, and only the audit told me it mattered.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>composer</category>
      <category>security</category>
      <category>devops</category>
    </item>
    <item>
      <title>Laravel's Built-In JSON:API Resources vs timacdonald/json-api vs laravel-json-api: Which One Your API Needs</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Thu, 29 Oct 2026 05:15:10 +0000</pubDate>
      <link>https://dev.to/hafiz619/laravels-built-in-jsonapi-resources-vs-timacdonaldjson-api-vs-laravel-json-api-which-one-your-17ml</link>
      <guid>https://dev.to/hafiz619/laravels-built-in-jsonapi-resources-vs-timacdonaldjson-api-vs-laravel-json-api-which-one-your-17ml</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/laravel-json-api-resources-vs-timacdonald-vs-laravel-json-api" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;On Laravel 13.38.0, a request for 20 posts with &lt;code&gt;?include=author,comments&lt;/code&gt; ran 41 queries through the framework's own JSON:API resources. The fix is merged into the 13.x branch. It just isn't in a release yet.&lt;/p&gt;

&lt;p&gt;I found that while building the same small API three ways: with Laravel's built-in &lt;code&gt;JsonApiResource&lt;/code&gt;, with &lt;a href="https://github.com/timacdonald/json-api" rel="noopener noreferrer"&gt;timacdonald/json-api&lt;/a&gt;, and with &lt;a href="https://laraveljsonapi.io" rel="noopener noreferrer"&gt;laravel-json-api/laravel&lt;/a&gt;. Same three models (users, posts, comments), same 20 posts and 100 comments, on a clean Laravel 13.38.0 project with SQLite. Each request went through a small middleware that counts queries. All output below is real.&lt;/p&gt;

&lt;p&gt;Two of the three look almost the same from the outside. The third is a different kind of tool. One question tells you which you need. (If you're still deciding how the API itself should behave, &lt;a href="https://hafiz.dev/blog/laravel-api-development-restful-best-practices" rel="noopener noreferrer"&gt;my production API practices post&lt;/a&gt; is the place to start.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Check your version first
&lt;/h2&gt;

&lt;p&gt;If you already use the built-in resources, three things depend on your Laravel version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GHSA-5wcm-3v2w-8362.&lt;/strong&gt; A &lt;a href="https://github.com/laravel/framework/security/advisories/GHSA-5wcm-3v2w-8362" rel="noopener noreferrer"&gt;moderate advisory&lt;/a&gt;, published on 19 October. A crafted request to a read-only endpoint could trigger a destructive operation on a related table through relationship inclusion. It affects 12.45.0 up to 12.68.0, and every 13.x release before 13.27.0. Fixed in 12.68.0 and 13.27.0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nested includes from 13.27 to 13.36.&lt;/strong&gt; Release 13.27.0 also changed how resources load relationships (&lt;a href="https://github.com/laravel/framework/pull/61322" rel="noopener noreferrer"&gt;#61322&lt;/a&gt;). From then on, nested includes ran one query per related model until &lt;a href="https://github.com/laravel/framework/pull/62000" rel="noopener noreferrer"&gt;#62000&lt;/a&gt; fixed it in 13.37.0. I installed each version and ran the same request, a user with 20 posts and 5 comments per post:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /api/builtin/users/1?include=posts.comments.author

13.26.0    4 queries
13.36.0  122 queries
13.38.0    4 queries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Collection includes, on every release so far.&lt;/strong&gt; &lt;a href="https://github.com/laravel/framework/pull/62000" rel="noopener noreferrer"&gt;#62000&lt;/a&gt; fixed single resources. Collections still load each item's includes one model at a time. This one predates the regression. &lt;a href="https://github.com/laravel/framework/issues/61252" rel="noopener noreferrer"&gt;Issue #61252&lt;/a&gt; reported 101 queries for 100 records on 13.24. The fix is &lt;a href="https://github.com/laravel/framework/pull/62152" rel="noopener noreferrer"&gt;#62152&lt;/a&gt;, merged on 22 October, two days after 13.38.0 shipped:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                                  13.26.0   13.36.0   13.38.0   13.x-dev
GET /posts?include=author              21        21        21          2
GET /posts?include=author,comments     41        41        41          3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Until the next tag, eager-load whatever the client asked for. The resource skips relations that are already loaded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/posts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$includes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_intersect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nb"&gt;explode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;','&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'include'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'author'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'comments'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'comments.author'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;PostResource&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$includes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /api/builtin/eager/posts?include=author             2 queries
GET /api/builtin/eager/posts?include=author,comments    3 queries
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I diffed the response bodies against the version without &lt;code&gt;with()&lt;/code&gt;, and they were identical. Keep the allow-list. Eloquent resolves each name passed to &lt;code&gt;with()&lt;/code&gt; by calling it as a method on a fresh model instance, so a raw &lt;code&gt;include&lt;/code&gt; string lets the client choose which method runs. (If you want the wider picture on spotting N+1 queries, &lt;a href="https://hafiz.dev/blog/laravel-query-optimization-from-3-seconds-to-30ms" rel="noopener noreferrer"&gt;my query optimization post&lt;/a&gt; walks through it.)&lt;/p&gt;

&lt;h2&gt;
  
  
  The built-in JsonApiResource
&lt;/h2&gt;

&lt;p&gt;It arrived in Laravel 12.45.0 (&lt;a href="https://github.com/laravel/framework/pull/57571" rel="noopener noreferrer"&gt;#57571&lt;/a&gt;) and is documented in the &lt;a href="https://laravel.com/docs/13.x/eloquent-resources#jsonapi-resources" rel="noopener noreferrer"&gt;API resources docs&lt;/a&gt;. &lt;code&gt;php artisan make:resource PostResource --json-api&lt;/code&gt; generates a class with two properties, and filling them in is most of the work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Http\Resources&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Http\Resources\JsonApi\JsonApiResource&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PostResource&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;JsonApiResource&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$attributes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'body'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$relationships&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'author'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;UserResource&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'comments'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both relationships resolve on their own. The built-in finds &lt;code&gt;CommentResource&lt;/code&gt; and &lt;code&gt;UserResource&lt;/code&gt; from the related models, so the explicit class on &lt;code&gt;author&lt;/code&gt; is optional. I kept it to show the syntax. A route returns it like any resource, and sparse fieldsets and includes work from the query string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /api/builtin/posts/1?include=author&amp;amp;fields[posts]=title&amp;amp;fields[users]=name
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"posts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"attributes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Post 1"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"relationships"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"users"&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"included"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"users"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"attributes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Hafiz"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response goes out as &lt;code&gt;application/vnd.api+json&lt;/code&gt;. A paginator gives you &lt;code&gt;first&lt;/code&gt;, &lt;code&gt;last&lt;/code&gt;, &lt;code&gt;prev&lt;/code&gt; and &lt;code&gt;next&lt;/code&gt; links, with Laravel's usual pagination meta and a plain &lt;code&gt;?page=2&lt;/code&gt; parameter. Nesting stops at five levels by default, and &lt;code&gt;JsonApiResource::maxRelationshipDepth()&lt;/code&gt; changes that. &lt;code&gt;toLinks()&lt;/code&gt; and &lt;code&gt;toMeta()&lt;/code&gt; add per-resource links and meta.&lt;/p&gt;

&lt;p&gt;That's the whole job. The built-in shapes responses. It doesn't read JSON:API requests or enforce the rest of the spec, and three gaps showed up straight away.&lt;/p&gt;

&lt;p&gt;It ignores include paths it doesn't know. &lt;code&gt;?include=secrets&lt;/code&gt; returned 200 with the post and no error. The &lt;a href="https://jsonapi.org/format/" rel="noopener noreferrer"&gt;JSON:API spec&lt;/a&gt; says a server that can't identify a relationship path "MUST respond with 400 Bad Request".&lt;/p&gt;

&lt;p&gt;Errors come out in Laravel's own format, not as JSON:API error objects. Here's a 422 from a POST route I wrote by hand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"The data.attributes.title field is required. (and 1 more error)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"errors"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;&lt;span class="nl"&gt;"data.attributes.title"&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="s2"&gt;"The data.attributes.title field is required."&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="nl"&gt;"data.attributes.body"&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="s2"&gt;"The data.attributes.body field is required."&lt;/span&gt;&lt;span class="p"&gt;]}}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And writes are yours to build. That route validates &lt;code&gt;data.type&lt;/code&gt; and &lt;code&gt;data.attributes.*&lt;/code&gt; with ordinary rules, then returns the new resource with a 201:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/posts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$validated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
        &lt;span class="s1"&gt;'data.type'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'in:posts'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="s1"&gt;'data.attributes.title'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'string'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'max:120'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="s1"&gt;'data.attributes.body'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'string'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;]);&lt;/span&gt;

    &lt;span class="nv"&gt;$post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$validated&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'data'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'attributes'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PostResource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setStatusCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;201&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works. But relationships in the request body, error objects with JSON pointers, and content negotiation are all on you. For filters and sorting, the docs point you at &lt;a href="https://spatie.be/docs/laravel-query-builder/" rel="noopener noreferrer"&gt;Spatie's Laravel Query Builder&lt;/a&gt;, which supports Laravel 12 and 13 in its current 7.x release (it needs PHP 8.4).&lt;/p&gt;

&lt;h2&gt;
  
  
  timacdonald/json-api
&lt;/h2&gt;

&lt;p&gt;Tim MacDonald's package has been around since its first release in November 2021, and the built-in uses the same property-based API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;TiMacDonald\JsonApi\JsonApiResource&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PostResource&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;JsonApiResource&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$attributes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'body'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$relationships&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'author'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;UserResource&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'comments'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;CommentResource&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I compared the package and the built-in on three requests (a single post with includes, the collection, and a user with sparse fieldsets). Once the keys were sorted, the documents were identical. Then I changed only the &lt;code&gt;use&lt;/code&gt; line in my three package resources to the built-in &lt;code&gt;Illuminate\Http\Resources\JsonApi\JsonApiResource&lt;/code&gt;, and the same three requests still returned identical documents.&lt;/p&gt;

&lt;p&gt;The other direction needs care. The package guesses the resource class from the relationship key, not from the related model, so &lt;code&gt;'author'&lt;/code&gt; with no class failed with a 500, because there's no &lt;code&gt;AuthorResource&lt;/code&gt;. Moving from the package to the built-in was the &lt;code&gt;use&lt;/code&gt; line. Moving from the built-in to the package can mean adding explicit classes.&lt;/p&gt;

&lt;p&gt;The difference is loading. The package doesn't eager-load by design, and its README says so plainly. It recommends Spatie's query builder for that job. Without it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /api/tim/users/1?include=posts.comments.author    123 queries
GET /api/tim/posts?include=author                      22 queries
GET /api/tim/posts?include=author,comments             43 queries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the same &lt;code&gt;with()&lt;/code&gt; allow-list from earlier, those collection requests dropped to 2 and 3 queries.&lt;/p&gt;

&lt;p&gt;It's still a pre-release. The latest tag is 1.0.0-beta.12, from March 2026. The repository isn't archived, and its constraints cover Laravel 11, 12 and 13. That makes it the right choice on Laravel 11, or on a 12.x app older than 12.45.0. On anything newer I wouldn't start a new API on it, because the built-in gives you the same API from the framework itself, and the N+1 fix lands in the framework too. If you're already on it, my migration for these three resources was the &lt;code&gt;use&lt;/code&gt; line.&lt;/p&gt;

&lt;h2&gt;
  
  
  laravel-json-api/laravel
&lt;/h2&gt;

&lt;p&gt;This is a different kind of tool. It isn't a resource class, it's a full JSON:API server. Version 5.3.0 (July 2026) supports Laravel 12.61.1 and up and 13.x.&lt;/p&gt;

&lt;p&gt;Setup is more work. I published the config, generated a server with &lt;code&gt;php artisan jsonapi:server v1&lt;/code&gt;, registered it in &lt;code&gt;config/jsonapi.php&lt;/code&gt;, generated three schemas and a request class, registered routes, and added its exception renderer in &lt;code&gt;bootstrap/app.php&lt;/code&gt;. A schema describes fields instead of output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PostSchema&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Schema&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$maxDepth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="no"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="nc"&gt;Str&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'title'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;sortable&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="nc"&gt;Str&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'body'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nc"&gt;BelongsTo&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'author'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'users'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nc"&gt;HasMany&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'comments'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nc"&gt;DateTime&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'createdAt'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;sortable&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;readOnly&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="nc"&gt;DateTime&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'updatedAt'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;sortable&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;readOnly&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;filters&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="nc"&gt;WhereIdIn&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nc"&gt;Where&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'author'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'user_id'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;pagination&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;?Paginator&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;PagePagination&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;make&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;JsonApiRoute&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'v1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'v1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;resources&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'posts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;JsonApiController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;relationships&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$relations&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$relations&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasOne&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'author'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;readOnly&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="nv"&gt;$relations&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'comments'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;readOnly&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'users'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;JsonApiController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;only&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'index'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'show'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That route block registered create, update and delete for posts, plus the related-resource and relationship endpoints (&lt;code&gt;/posts/{post}/author&lt;/code&gt;, &lt;code&gt;/posts/{post}/relationships/comments&lt;/code&gt;), with no controller code of mine.&lt;/p&gt;

&lt;p&gt;Then it does the things the built-in leaves to you. Includes are eager-loaded with no help:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /api/v1/users/1?include=posts.comments.author    4 queries
GET /api/v1/posts?include=author                     2 queries
GET /api/v1/posts?include=author,comments            3 queries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Include paths are validated. The default &lt;code&gt;$maxDepth&lt;/code&gt; is 1, which is why the schema above raises it. Before I did, the nested request came back like this, and so does any path the schema doesn't declare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"jsonapi"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"1.0"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="nl"&gt;"errors"&lt;/span&gt;&lt;span class="p"&gt;:[{&lt;/span&gt;&lt;span class="nl"&gt;"detail"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Include path posts.comments.author is not allowed."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;&lt;span class="nl"&gt;"parameter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"include"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"400"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Invalid Query Parameter"&lt;/span&gt;&lt;span class="p"&gt;}]}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;?filter[author]=2&lt;/code&gt;, &lt;code&gt;?sort=-title&lt;/code&gt; and &lt;code&gt;?page[number]=2&amp;amp;page[size]=5&lt;/code&gt; worked straight away. Writes are validated against the request class, and the errors point at the exact member of the request document:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;422 Unprocessable Entity | The title field is required. | /data/attributes/title
422 Unprocessable Entity | The body field is required. | /data/attributes/body
422 Unprocessable Entity | The author field is required. | /data/relationships/author
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A POST with a plain &lt;code&gt;application/json&lt;/code&gt; body was refused with a 415. A proper document, with the author passed as a relationship, created the post and returned it with a 201.&lt;/p&gt;

&lt;p&gt;Two costs to know about. Authorization runs through your policies by default. I switched it off for this test with &lt;code&gt;authorizable()&lt;/code&gt; returning false on the server, but in a real app you'd write the policies (my &lt;a href="https://hafiz.dev/blog/laravel-policies-vs-gates-authorization-guide" rel="noopener noreferrer"&gt;policies vs gates guide&lt;/a&gt; covers those). And it brings its own conventions, like camelCase &lt;code&gt;createdAt&lt;/code&gt;, its own controller, and a schema layer your team has to learn.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which one your API needs
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Built-in &lt;code&gt;JsonApiResource&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;timacdonald/json-api&lt;/th&gt;
&lt;th&gt;laravel-json-api/laravel&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;What it is&lt;/td&gt;
&lt;td&gt;Resource classes&lt;/td&gt;
&lt;td&gt;Resource classes&lt;/td&gt;
&lt;td&gt;Full server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Minimum Laravel&lt;/td&gt;
&lt;td&gt;12.45.0&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;12.61.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Eager-loads includes&lt;/td&gt;
&lt;td&gt;Single resources (13.37+), collections not yet&lt;/td&gt;
&lt;td&gt;No, by design&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unknown include path&lt;/td&gt;
&lt;td&gt;Ignored, 200&lt;/td&gt;
&lt;td&gt;Ignored, 200&lt;/td&gt;
&lt;td&gt;400 error object&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filters, sorting&lt;/td&gt;
&lt;td&gt;Spatie Query Builder&lt;/td&gt;
&lt;td&gt;Spatie Query Builder&lt;/td&gt;
&lt;td&gt;Built in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Writes and validation&lt;/td&gt;
&lt;td&gt;Your code&lt;/td&gt;
&lt;td&gt;Your code&lt;/td&gt;
&lt;td&gt;Request classes, JSON pointers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Error format&lt;/td&gt;
&lt;td&gt;Laravel's&lt;/td&gt;
&lt;td&gt;Laravel's&lt;/td&gt;
&lt;td&gt;JSON:API error objects&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Status&lt;/td&gt;
&lt;td&gt;First-party&lt;/td&gt;
&lt;td&gt;1.0.0-beta.12&lt;/td&gt;
&lt;td&gt;5.3.0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The question that decides it is whether clients write through the API.&lt;/p&gt;

&lt;p&gt;If they only read, and what you need is the JSON:API shape for a front end or a mobile app, use the built-in. You get includes, sparse fieldsets and links from three small classes, and the remaining N+1 is a framework bug with a fix already merged. Add the &lt;code&gt;with()&lt;/code&gt; allow-list until it ships.&lt;/p&gt;

&lt;p&gt;If clients create and update resources through it, or a third party will build against your API and expects the spec enforced (error objects, rejected include paths, filters and pagination by the book), use laravel-json-api. Its setup cost is real, but you'd spend more than that rebuilding its validation and errors by hand on top of the built-in.&lt;/p&gt;

&lt;p&gt;And timacdonald/json-api is for apps that can't run the built-in yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Does Laravel's built-in JSON:API resource support filtering and sorting?
&lt;/h3&gt;

&lt;p&gt;No. It shapes responses and handles &lt;code&gt;include&lt;/code&gt; and &lt;code&gt;fields&lt;/code&gt;. The Laravel docs point to Spatie's Laravel Query Builder for filters and sorts, and its current 7.x release supports Laravel 12 and 13 on PHP 8.4.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can the built-in JsonApiResource accept JSON:API documents in POST or PATCH?
&lt;/h3&gt;

&lt;p&gt;Only through your own code. You validate &lt;code&gt;data.attributes.*&lt;/code&gt; with normal rules and create the model yourself. Validation errors come back in Laravel's default format, not as JSON:API error objects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is timacdonald/json-api abandoned?
&lt;/h3&gt;

&lt;p&gt;No. The repository isn't archived and the latest release, 1.0.0-beta.12, supports Laravel 11 to 13. It's still a pre-release, though, and on Laravel 12.45.0 or newer the built-in offers the same property-based API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does laravel-json-api reject my include with a 400?
&lt;/h3&gt;

&lt;p&gt;Either the path isn't a relationship on the schema, or it's deeper than the schema's &lt;code&gt;$maxDepth&lt;/code&gt;, which defaults to 1. The JSON:API spec requires a 400 when a server can't support an include path, and the package follows it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Which Laravel version fixes the JSON:API N+1 queries?
&lt;/h3&gt;

&lt;p&gt;Nested includes on a single resource are fixed in 13.37.0. Includes on collections are fixed on the 13.x branch by #62152, which was merged after 13.38.0 and should ship in the next 13.x release. Check the release notes for #62152 before you remove a &lt;code&gt;with()&lt;/code&gt; workaround.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Whichever you pick, run &lt;code&gt;composer show laravel/framework&lt;/code&gt; before you ship it. Anything from 13.27.0 to 13.36.0 loads nested includes one model at a time, and every release up to 13.38.0 does the same for collection includes until #62152 is tagged.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>apidevelopment</category>
      <category>eloquent</category>
      <category>performance</category>
    </item>
    <item>
      <title>Smoke</title>
      <dc:creator>Hafiz</dc:creator>
      <pubDate>Wed, 28 Oct 2026 10:48:04 +0000</pubDate>
      <link>https://dev.to/hafiz619/smoke-4b1g</link>
      <guid>https://dev.to/hafiz619/smoke-4b1g</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Originally published at &lt;a href="https://hafiz.dev/blog/smoke" rel="noopener noreferrer"&gt;hafiz.dev&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  Hi
&lt;/h1&gt;

&lt;p&gt;Body.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
