Did you trying using mysql's ping() function? mysql_ping/mysqli_ping ?