Too many connections

I have 170+ tests and after 152 i have error [1040] Too many connections In my tests i use DatabaseTransactions. Tried write protected $connectionsToTransact = ['mysql_test']; and

protected function setUpTraits()
    parent::setUpTraits(); // TODO: Change the autogenerated stub

    $uses = array_flip(class_uses_recursive(static::class));

    if (isset($uses[DatabaseMigrations::class])) {
        $this->beforeApplicationDestroyed(function () {

Perhaps someone already came across this and found a solution

Agelios replied 1 week ago

I tried also use 'options' => [ PDO::ATTR_PERSISTENT => true ] in database config. I had 1 connection but also had error PDOException: There is already an active transaction

Aiden Andrews-McDermott replied 3 days ago

Too many connection errors are your DB server refusing not your code.

Two ways I would combat this change the configuration on your DB server to allow more connections or go through all the tests and see that they are properly closing the connection to the database once it has finished running so that the next test can set up its own. Not having your code properly close your connection after your script runs can lead to you exhausting your DB Servers resources and potentially cause a Denial Of Service issue.

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us