Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm preparing my Laravel 5.5 production environment to run on multiple AWS EC2 instances behind an Elastic Load balancer (ELB). All shared data such as images, css, js are stored on S3, logs are streaming to CloudWatch, and the database is on RDS. Sessions and Cache have been configured to use database.

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.

So my question is this... Is there a method in Laravel to ignore or refuse requests from specific user_agents so they don't start a session? I could write a shell script to periodically delete the records but that seems like an unnecessary hack.

like image 991
gerion Avatar asked Sep 25 '17 18:09

gerion


2 Answers

I think the simplest solution would be to direct the ELB to a specific route for health check pings and then disable the session middleware for that route as mentioned here

like image 116
Paras Avatar answered Nov 09 '22 21:11

Paras


A simple solution (in your routes file):

    Route::get('/healthcheck', function() {
        config()->set('session.driver', 'array');
        return response('Hello World', 200)
           ->header('Content-Type', 'text/plain');
    });
like image 25
intheusa Avatar answered Nov 09 '22 21:11

intheusa