does laravel disconnect to database after each query?
I check on DB by command: show full processlist and see some sleep process.
I read some blog and they said laravel and php always disconect DB after finish query.
But in my DB still have some long time sleep process .
I know that I can set wait_timeout to reduce the sleep connection.
But my question is : Why laravel doesn't disconnect after each query
Please give me the answer . Thank you so much !
It doesn't have to be Laravel. Maybe some package is causing that. Or maybe your code. Who knows. List is endless. Are there multiple apps connecting to the same database? Hard to tell anything from what you've provided.
thank for your quick reply.
I can make sure that I only use one app for one database.
follow this blog: https://www.percona.com/blog/2007/02/08/debugging-sleeping-connections-with-mysql/
I can tracing the sleep process that it come from my app, it not come from the package. It come from the normal api .
But in my laravel code, I do not have any custom code to keep the connection running long time.
But in my laravel code, I do not have any custom code to keep the connection running long time.
Deploy clean Laravel app to use that same database. Add few models and run few cron jobs that access the database. Then see if you have additional sleeping processes. Maybe there is a bug in Laravel, but I doubt that cause there are so many developers and projects using it that it would not go unnoticed for a long time.
Deploy clean Laravel app to use that same database. Add few models and run few cron jobs that access the database.
That sound good idea for investigate.
it may take time now , also my issue come from production env.
the sleep connection may not consum more CPU RDS but it occupied the connection in max connection we have..
stop php-fpm, restart mysql, look for sleep process. start php-fpm, look for sleep process. update some pages, look for sleep process.
i think it php mechanic, but it not are problem.