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

ahmeda's avatar

Laravel Sessions database table filling up with user_agent ELB-HealthChecker/2.0

I just deploy my Laravel app production environment to run on EB(elastic beanstalk) It's all working great except I'm seeing the sessions table filling up with thousands of ELB health checks with user_agent "ELB-HealthChecker/2.0". Laravel/PHP apparently sees each health check as a new user and generates a new session, one every 30 seconds from each instance. This could get out of hand real quick and would not be sustainable.

Is there a method in Laravel to ignore or refuse requests from specific user_agents so they don't start a session?

0 likes
1 reply
s4muel's avatar
s4muel
Best Answer
Level 50

create a new middleware that sets the session driver to an array if user agent string matches the healthcheck. put (register) it before StartSession middleware in Kernel.php

middleware could look something like this:

<?php

namespace App\Http\Middleware;

use Illuminate\Support\Facades\Config;

class NoSessionForHealthCheck
{
    /**
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (request()->header('User-Agent') && strpos(request()->header('User-Agent'), 'ELB-HealthChecker') !== false) {
            Config::set('session.driver', 'array');
        }

        return $next($request);
    }
}
2 likes

Please or to participate in this conversation.