Have you tried mysql_ping()?
Update: From PHP 5.5 onwards, use mysqli_ping() instead.
Pings a server connection, or tries to reconnect if the connection has gone down.
if ($mysqli->ping()) {
printf ("Our connection is ok!
");
} else {
printf ("Error: %s
", $mysqli->error);
}
Alternatively, a second (less reliable) approach would be:
$link = mysql_connect('localhost','username','password');
//(...)
if($link == false){
//try to reconnect
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…