http://php.net/manual/ru/function.mysql-ping.php
<?php
function database_connect() {
$conn = mysql_connect('localhost', 'username', 'password');
mysql_select_db('database', $conn);
return $conn;
}
$conn = database_connect();
if (!mysql_ping($conn)) {
// the previous connection must be closed (even if it was dropped) to reinitialize correctly
mysql_close($conn);
// reconnect
$conn = database_connect();
}
в php.ini Если используется mysqli модуль
то mysqli.reconnect = On