Heyo,
I’m using the Yiisoft Yii 3 DI in my Redis message queue script, and while testing my retry-loop, I’m getting “Too many connections” error from MySQL.
My container and injector are in a function that ends after each retry.
function process_task($task)
{
// omitted code...
$task_data = $task[1];
$message = unserialize($task_data);
$container = new Container($diConfig);
$injector = new Injector($container);
// This will create a new Db class with a new PDO connection
$result = $message($injector);
// Check result...
}
Looks like something is still dangling?
When I close the connection explicitly, I don’t get the error.
Still on PHP 7.4, so I’m using
"yiisoft/di": "^1.1",
"yiisoft/injector": "^1.2",
The Redis script uses a while(true) { ... process ... }
loop, together with supervisor to keep the script running if it fails. But maybe it’s better to rely only on supervisor without such a loop? To close the entire PHP environment after each successful message.