Ok, so I wasted about 3 hours on this, and have only sort of found a solution. I have a PHP script which is going to be running 24/7 checking a message queue and then interacting with a database when a message is received. It was mostly working, until it sat there for a day and I tried to use it the next day. The PHP script had quit, with the error "MySQL server has gone away." I figured there must be some sort of time limit that the mysql server will keep an idle connection alive. I couldn't find it, but luckily I was talking to nick, and he did! He found this blog entry. So I changed the my.cnf file to set the timeout to one week:
wait_timeout=604800
interactive_timeout=604800
That'll do for now. The other alternative would be to check if the connection is alive before running a query, and connecting if it isn't. I couldn't get that one to work, though.