To persist or not to persist?
Recently, in a new PHP + MySQL application I'm building, I was faced with a choice of using persistent connections. The benefit of persistent connections is that you don't have to keep opening new connections every time you need to hit the database for something. There's a connection already waiting for you. Yay, right? Well, with MySQL, connecting is actually really really cheap, and frankly, if you are using persistent connections, you might encounter some issues with Apache going zombie on processes that use a connection, effectively taking that connection out of use. Grrr.
"To Google!", I said. "The Interwebs must have a solution for this!" I've searched and searched trying to find a definite answer about whether to use or not to use persistent connections in a LAMP application. There seem to be lots of differing opinions, namely this famous presentation by Rasmus which basically "proves" that persistent connections are awesome. However, the PHP community seemed to be pretty against them, despite that evidence.
At this point, it was just annoying. Do I use persistent connections or not? Having this conversation internally with Ben Ramsey and Robert Swarthout, it seemed a good idea to have some hard numbers to back up our claims, so we wouldn't have to say "well, guy x said so" as part of the argument.
Here are the results of Robert's tests: Benchmarking of MySQL Persistent Connections vs Non-Persistent Connections. As Robert says:
Basically what the numbers above shows us is that in an isolated environment it makes no difference which connection type you are going to use.
Jay Pipes says that "if you use Apache, Apache can zombie a PHP process and cause the mysql connection to be held until the mysql server restarts..." Given the risk, the possible management overhead and the results of the test, we're not going to use persistent connections on this upcoming project.