6

The situation is: I have one Debian Server running LAMP with one Virtual Host with one Website. My MySQL has only one user from that website.

In this case would I benefit from using a persistent connection?

The PHP documentation seems to advise against persistent connections in any case.

Thanks


Edit: Yes, the MySQL server is on the same machine.

F. Orvalho
  • 576
  • 4
  • 12
dynamic
  • 46,985
  • 55
  • 154
  • 231

2 Answers2

7

There's a discussion here http://groups.google.com/group/comp.databases.mysql/browse_thread/thread/4ae68befe1b488e7/e843f0b9e59ad710?#e843f0b9e59ad710 :

"No, it is not (better). Contrary, using mysql_pconnect() is considered harmful, as it tends to hog the MySQL server with idle connections."

If you connect via 'localhost', the connection will automatically be established via the MySQL socket, which is really cheap anyways.

(Groups link taken from MySQL Persistent Connections)

Community
  • 1
  • 1
konsolenfreddy
  • 9,551
  • 1
  • 25
  • 36
  • everyone saying persisent sux, so who use them? oO And for the idle connections, what do you mean? I will establish only 1 connection considering I have only 1 mysql uyser – dynamic Mar 16 '11 at 10:30
  • 1
    Thats the point, persistent connections should idle the MySQL connection when not in use.. If its helpful or not depends on the bottleneck and the code architecture. Everything is harmful if you don't know how to use it. – Dennis Feb 07 '13 at 13:33
0

While you can get some performance benefits from using a persistent connection, but if the mysql server is on the same machine and you're not experiencing problems then it is probably not worth it. It is too easy to accidentally leave connections open, and the actual performance benefit is only going to be noticeable at high volumes.

Hamish
  • 22,860
  • 8
  • 53
  • 67
  • Define High volumes? A couple of connections per second is high volume? And yes the mysql is on the same machine – dynamic Mar 16 '11 at 09:15
  • 1
    High volume really depends on the settings and machine you have. Though I'd say the average falls more along the lines of a few hundred to a few thousand connections per second these days. Even that's light when you look at the massive numbers Facebook pushes of something like approx. 100.3 million connections per second. – Shawn Solomon Mar 21 '12 at 06:35