0

I'm using symfony 1.4/propel 1.4 for a project, which was made by other developer earlier. On that project, propel connection is taken by using following code

$con = Propel::getConnection(UsersPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);

However it never closes the connection using

Propel::close();

I just searched that there are 1500+ such incidents of opening connection & I guess none of them is closing connection.

I know its always good practice to close connection but in present case, it seems I wont be able to fix them all as fixing all the incidents is definitely going to take lot of time, may be a whole day. So now I'm confused if I should fix that or not. If I let it be like that, will it have any performance impact?

EDIT: Just for reference

Part 2 of this question Use of closing database connection in php

Community
  • 1
  • 1
Kapil Sharma
  • 10,135
  • 8
  • 37
  • 66
  • Do they connect to Propel each time ?! Theorically it's done by Symfony and you don't have to manage the opening/closing. By the way, I guess PHP close the connection at the end of each script if you don't tell it to explicit do it. This usually perform on the `__destruct` object. See [this question/answers](http://stackoverflow.com/questions/6809248/mysql-database-connection-not-closed-what-will-happen). – j0k Sep 11 '12 at 08:25
  • Not always but mostly in case of transaction operation. However I found few places where it is happening for simple query too. – Kapil Sharma Sep 11 '12 at 08:40

1 Answers1

1

If anything, explicitly closing connections may harm performance. PDO often caches connections from one request to the next, on the reasonable assumption that the next request will use the same credentials.

Edit: reading the docs, it looks to me like PDO::ATTR_PERSISTENT connections are cached regardless of any attempt to close them, so you might as well not bother.

Rob Agar
  • 12,337
  • 5
  • 48
  • 63
  • By first para, does it mean "one should not close the connection" explicitly? If yes, what is the recommended use of Propel::close() – Kapil Sharma Sep 11 '12 at 08:48
  • IMHO, I don't think you ever really need to call close(). And I wouldn't worry about calling getConnection() over and over again - Propel has it's own connection caching, so you're just getting the same connection back each time. – Rob Agar Sep 11 '12 at 08:54