What's between StartSession and ShareErrorsFromSession middlewares?
My Laravel APP became slow suddenly. It happens on the server only. It takes around 5 seconds to respond with very simple requests.
After debugging in Production I found that:
Problem happens after StartSession middleware calls $response = $next($request); inside handleStatefulRequest method. And I can see that $next closure contains ShareErrorsFromSession middleware.
But when I do dd inside ShareErrorsFromSession handle method or even in it's constructor it takes around 5 seconds to reach that.
So somewhere in between StartSession and ShareErrorsFromSession middlewares something takes 5 seconds to do it's job.
I tried changing SESSION_DRIVER to file, database, redis but it didn't make any difference.
Any ideas what's between them and how to debug it?
Your issue is likely caused by session handling delays. Since the slowdown happens between StartSession and ShareErrorsFromSession, try disabling session locking (SESSION_LOCKING=false) if using Redis, reducing session lifetime (SESSION_LIFETIME=1), or checking disk I/O if using file storage (iostat -xm 1 10). For database sessions, inspect slow queries (SHOW PROCESSLIST). You can also add logging inside StartSession to measure execution time or disable middleware one by one to isolate the issue. If your app depends on external APIs, DNS, or NFS, check logs (storage/logs/laravel.log) for delays and test DNS resolution (dig example.com). Finally, clearing cache and config (php artisan cache:clear && php artisan config:clear) might help resolve the issue.
Did you find a solution? I've got the same problem, tried everything and still very slow, about 4 sec to load a page that just include the web middleware without anything else.
I tried to make a call to a route that exclude the middleware (withoutMiddleware('web')) and it is very fast.