A member of the team came to me the other day with a MySQL error that I’d not seen before:
Lost connection to MySQL server during query
The MySQL manual (http://dev.mysql.com/doc/refman/5.0/en/gone-away.html) says that it can be caused by:
applications that fork child processes, all of which try to use the same connection to the MySQL server
Which was exactly our case as we were creating a benchmarking tool that created child processes to concurrently query the website. So we checked the code to make sure that no database connections were shared between processes, and also that all connections were closed immediately after being used… but we still got the same error.
After a few minutes of scratching our heads, it dawned on us that we were using persistent connections, and of course when connection objects are destroyed the actual connections are not closed but are returned to a pool of connections, ready for re-use.
We changed the connections to non-persistent and Bob was our proverbial uncle!