in reply to mysql_auto_reconnect
Just to explain what is happening,
The connection is lost after wait_timeout seconds of inactivity (SHOW VARIABLES in MySQL). That is why your database connections are closed after this period. You can alter this period in the my.cnf file.
Marcel