Doctrine 2 Close Connection

后端 未结 3 1279
一整个雨季
一整个雨季 2021-02-20 00:26

I use doctrine 2 PDO with mysql.

When stress testing the server, mysql reports a lot of aborted connections (up-to 20%).

I am trying to locate the issue.

相关标签:
3条回答
  • 2021-02-20 00:41

    I have the same problem and

    $entityManager->getConnection()->close(); 
    

    seems to work, but works 'better' in some php versions if you add

     gc_collect_cycles() 
    

    after closing connections. I'm still having that kind of issues in older php version, may be something related with the garbage collector I guess. Will keep you updated if I find a final solution for all php versions

    0 讨论(0)
  • 2021-02-20 00:47

    I have found this tweak:

    https://sroze.io/phpunit-mysql-too-many-connections-error-ab52cd5798c5

    Setting processIsolation="true" option in PhpUnit XML options file seems to do the trick.

    0 讨论(0)
  • 2021-02-20 00:59

    From what I've observed, Doctrine uses persistent connections.

    We've stumbled upon a problem, launching unit tests in symfony2, where the database was spammed with connections in "Sleep" status. The solution that worked for us:

    $entityManager->getConnection()->close();
    
    0 讨论(0)
提交回复
热议问题