Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uchamb's avatar
Level 1

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?

0 likes
4 replies
Sinnbeck's avatar

When you change that env be sure to clear cache php artisan optimize:clear and if you are using opcache try restarting php fpm as well

nuligiarsyani's avatar

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.

Bik's avatar

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.

Glukinho's avatar

@Bik

  1. see which exact middlewares (no middleware groups) are applied to your route using php artisan route:list -vv

  2. exclude middlewares one by one using

  • either $middleware->remove(Middleware::class) in AppServiceProvider (for global middlewares)
  • or ->withoutMiddleware(Middleware::class) for route middleware
  1. see which middleware produces the delay (in other words, after disabling which middleware the delay disappears)

  2. inspect that middleware code and try to understand what can make that delay.

Please or to participate in this conversation.