Database | Blog | Mozex                        [ Skip to content ](#main-content)   [                  ozex Labs ](https://mozex.dev) [About](https://mozex.dev#about) [Projects](https://mozex.dev#projects) [Open Source](https://mozex.dev#open-source) [Services](https://mozex.dev#services) [Docs](https://mozex.dev/docs) [Blog](https://mozex.dev/blog) [ Get in Touch ](https://mozex.dev#contact) 

        [About](https://mozex.dev#about) [Projects](https://mozex.dev#projects) [Open Source](https://mozex.dev#open-source) [Services](https://mozex.dev#services) [Docs](https://mozex.dev/docs) [Blog](https://mozex.dev/blog) [ Get in Touch ](https://mozex.dev#contact) 

     [   Back to Blog ](https://mozex.dev/blog) Tagged: Database 
==================

     [ Laravel Deadlocks: Queue Jobs That Already Ran End Up in failed\_jobs 
-----------------------------------------------------------------------

 ](https://mozex.dev/blog/31-laravel-deadlocks-queue-jobs-that-already-ran-end-up-in-failed-jobs) I queued 2,000 jobs in a scratch Laravel 13.33.0 app and ran them through eight php artisan queue:work processes against MySQL 5.7. All 2,000 ran. When the workers stopped, 76 of them were still in the jobs table, reserved, and the log had lines that start like this one: \[2026-09-23 20:05:01\] local.ERROR: SQLSTATE\[40001\]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction (Connection: mysql, Host: 127.0.0.1, Port: 41357, Database: dl, SQL: delete from `jobs` where `id` = 1664) About 90 seconds later a worker picked the 76 up and moved every one of them to failed\_jobs with "App\\Jobs\\Probe has been attempted too many times." None of them had failed. Each had finished its work before its row deadlocked.

   Oct 5, 2026   ·  9 min read   ·  [ Laravel ](https://mozex.dev/blog/tags/laravel) [ PHP ](https://mozex.dev/blog/tags/php) [ DevOps ](https://mozex.dev/blog/tags/devops) [ Database ](https://mozex.dev/blog/tags/database)  

  [ Laravel Tests Fail When Two Runs Overlap, Even With --parallel 
----------------------------------------------------------------

 ](https://mozex.dev/blog/29-laravel-tests-fail-when-two-runs-overlap-even-with-parallel) Whenever two test commands ran inside one of my projects at the same time, they failed, because one run would clear the database under the other. It happened especially when I asked a Claude Code session to hand work to sub-agents: each sub-agent ran the tests for its own change, the runs failed, and it became a loop of discovering the problem and running it again. For this post I reproduced it on a fresh Laravel app whose phpunit.xml points at MySQL, with 1,201 tests, 1,200 of them using RefreshDatabase. Run alone, before any fix, the suite passes in under a minute. I started php artisan test twice at the same moment, three times. All six runs failed 1,167 to 1,200 of their 1,201 tests, and each took 3.5 to 4.4 minutes. The fix is my package mozex/laravel-test-lanes. Install it with composer require mozex/laravel-test-lanes --dev and there's nothing else to set up. With it, those runs pass. Everything here ran on Laravel 13.33, PHP 8.5, PHPUnit 12.5 with ParaTest 7.20, and MySQL 8.4 on Windows 11, with version 1.1.1 of the package (Laravel 11 to 13, PHP 8.2+, MySQL, MariaDB and PostgreSQL).

   Sep 30, 2026   ·  7 min read   ·  [ Laravel ](https://mozex.dev/blog/tags/laravel) [ PHP ](https://mozex.dev/blog/tags/php) [ Testing ](https://mozex.dev/blog/tags/testing) [ Open Source ](https://mozex.dev/blog/tags/open-source) [ Database ](https://mozex.dev/blog/tags/database)  

  [ Laravel chunk vs lazy vs cursor: lazy() Is as Slow as chunk() 
---------------------------------------------------------------

 ](https://mozex.dev/blog/26-laravel-chunk-vs-lazy-vs-cursor-lazy-is-as-slow-as-chunk) I seeded a MySQL table with 1,000,000 orders and walked through every row with each of five Laravel methods for iterating a big query: chunk(), chunkById(), lazy(), lazyById() and cursor(). chunkById() finished in 21.9 seconds and lazyById() in 22.3, neither above 5.9 MB of PHP memory. chunk() and lazy() held just as little and took about six times as long. cursor(), which the Laravel docs offer as a way to "significantly reduce your application's memory consumption", finished behind both ById methods and held 100.4 MB.

   Sep 23, 2026   ·  9 min read   ·  [ Laravel ](https://mozex.dev/blog/tags/laravel) [ PHP ](https://mozex.dev/blog/tags/php) [ Performance ](https://mozex.dev/blog/tags/performance) [ Database ](https://mozex.dev/blog/tags/database)  

  [ The Laravel Bug Your Tests Will Never Catch 
---------------------------------------------

 ](https://mozex.dev/blog/16-the-laravel-bug-your-tests-will-never-catch) In a previous post, I listed "your job runs before the data exists" as one of five queue failures that only show up in production. I showed the afterCommit() fix and moved on. But that post didn't answer the question that kept nagging me: why do your tests always pass when this bug is sitting right in your code? And where else in your app is this same timing problem hiding, beyond direct dispatch() calls? This post digs into both.

   Apr 15, 2026   ·  7 min read   ·  [ Laravel ](https://mozex.dev/blog/tags/laravel) [ PHP ](https://mozex.dev/blog/tags/php) [ Testing ](https://mozex.dev/blog/tags/testing) [ Database ](https://mozex.dev/blog/tags/database)  

  [ A Practical Guide to Database Indexing in Laravel 
---------------------------------------------------

 ](https://mozex.dev/blog/14-a-practical-guide-to-database-indexing-in-laravel) Your queries work fine in development. Fifty rows, instant responses, no complaints. Then you deploy to production, real data piles up, and a page that loaded in 200ms takes four seconds. The problem usually isn't your Eloquent code. It's the indexes you forgot to add.

   Apr 9, 2026   ·  11 min read   ·  [ Laravel ](https://mozex.dev/blog/tags/laravel) [ PHP ](https://mozex.dev/blog/tags/php) [ Tutorial ](https://mozex.dev/blog/tags/tutorial) [ Performance ](https://mozex.dev/blog/tags/performance) [ Database ](https://mozex.dev/blog/tags/database)  

###  Stay in the Loop 

 Get the latest posts delivered to your inbox - on your schedule.

   Every New Post Weekly Digest Monthly Digest  

  Subscribe   Subscribing...     No spam. Unsubscribe anytime.

   ![Mozex](https://mozex.dev/images/mozex/profile-256.webp)###  Mozex 

 Laravel Specialist

 Senior Laravel Specialist &amp; Consultant. Building developer tools and open-source packages.

 [   ](https://github.com/mozex) [   ](https://www.linkedin.com/in/mozex) [   ](https://x.com/mozexdev) [   ](https://mozex.dev/blog/feed) 

###  Browse by Topic 

  [ Laravel  22  ](https://mozex.dev/blog/tags/laravel) [ PHP  22  ](https://mozex.dev/blog/tags/php) [ Open Source  7  ](https://mozex.dev/blog/tags/open-source) [ DevOps  6  ](https://mozex.dev/blog/tags/devops) [ Database  5  ](https://mozex.dev/blog/tags/database) [ Developer Tools  4  ](https://mozex.dev/blog/tags/developer-tools) [ AI  4  ](https://mozex.dev/blog/tags/ai) [ Claude Code  3  ](https://mozex.dev/blog/tags/claude-code) [ Testing  3  ](https://mozex.dev/blog/tags/testing) [ Performance  3  ](https://mozex.dev/blog/tags/performance) [ Architecture  3  ](https://mozex.dev/blog/tags/architecture) [ Tutorial  3  ](https://mozex.dev/blog/tags/tutorial) [ Bash  2  ](https://mozex.dev/blog/tags/bash) [ Anthropic  2  ](https://mozex.dev/blog/tags/anthropic) [ WooCommerce  2  ](https://mozex.dev/blog/tags/woocommerce) [ Productivity  1  ](https://mozex.dev/blog/tags/productivity) [ Markdown  1  ](https://mozex.dev/blog/tags/markdown) [ MCP  1  ](https://mozex.dev/blog/tags/mcp) [ GitHub Actions  1  ](https://mozex.dev/blog/tags/github-actions) [ Pest  1  ](https://mozex.dev/blog/tags/pest) [ Code Review  1  ](https://mozex.dev/blog/tags/code-review) [ Windows  1  ](https://mozex.dev/blog/tags/windows)  

###  Need expert Laravel help? 

 I offer consulting, code reviews, and custom development for Laravel applications.

 [ View Services   ](https://mozex.dev#services) 

   Live across open source

  1,407,518+  

 package downloads and counting

  Mozex Labs  [     Iminify, our free image compressor ](https://www.iminify.com) 

 [   ](https://github.com/mozex) [   ](https://www.linkedin.com/in/mozex) [   ](https://x.com/mozexdev) [   ](mailto:hello@mozex.dev) [   ](https://mozex.dev/blog/feed) 

  © 2026 Mozex Labs
