I have migrated my PHP application to a serverless model where the cloud provider limits the amount of active connections between a container instance and the MySQL server. Sometimes during the week, this limit of 100 active connections to MySQL per container instance is exceeded . The SQL client library used in PHP is Medoo, an abstraction of PDO, we use PHP 7.3 and Slim Framework 3.
When checking the SHOW PROCESSLIST; from the MySQL server, it is possible to see several connections that are already old and with sleep status, why weren't they closed? According to the PDO documentation, PHP closes MySQL connections when finishing the script, are there any exceptions in this "end script" condition? When does the script ends? Is there some Apache or PHP config that may be avoiding this and causing the problem?
After contextualizing you, the reader, to the problem. My question is: What could be causing this? Are there any config in PHP or Apache that might be related to the issue? What should I pay attention to in the code? What would you try?
And no, we have not set persistent connections.