Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2 Close Connection

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.

Mysql manual suggests to ensure that connections to the database are closed properly. http://dev.mysql.com/doc/refman/5.0/en/communication-errors.html

I can't find any information if doctrine actually closes connections or not, or uses persistent connections.

Also, is there anything else that can account for aborted connections? I am at loss here.

PS. Server is ubuntu 10.04, nginx 1.x, php 5.3.5 (fpm) and mysql 5.1.41

like image 960
iBiryukov Avatar asked Aug 20 '11 20:08

iBiryukov


2 Answers

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();
like image 199
wdev Avatar answered Nov 20 '22 02:11

wdev


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

like image 1
Ignacio Vazquez Avatar answered Nov 20 '22 04:11

Ignacio Vazquez