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.
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
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');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With