mysql_ping
(PHP 4 >= 4.3.0, PHP 5)
mysql_ping — pinga uma conexão com o servidor ou reconecta se não houver conexão
Descrição
$link_identifier
] )Confere se uma conexão com um servidor esta funcionando ou não. Se ela tiver caído, tenta realizar uma conexão automatica. Esta função pode ser usada em scripts que permanecem inativos por um longo tempo, para conferir se o servidor fechou ou não a conexão e reconectar se necessário.
Note:
Desde o MySQL 5.0.13, o recurso de automática reconexão está desabilitada.
Parâmetros
-
link_identifier -
The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If no connection is found or established, an
E_WARNINGlevel error is generated.
Valor Retornado
Retorna TRUE se a conexão com o servidor MySQL esta funcionando,
se não retorna FALSE.
Exemplos
Example #1 Exemplo mysql_ping()
<?php
set_time_limit(0);
$conn = mysql_connect('localhost', 'mysqluser', 'mypass');
$db = mysql_select_db('mydb');
/* Assuming this query will take a long time */
$result = mysql_query($sql);
if (!$result) {
echo 'Query #1 failed, exiting.';
exit;
}
/* Make sure the connection is still alive, if not, try to reconnect */
if (!mysql_ping($conn)) {
echo 'Lost connection, exiting after query #1';
exit;
}
mysql_free_result($result);
/* So the connection is still alive, let's run another query */
$result2 = mysql_query($sql2);
?>
Veja Também
- mysql_thread_id() - Returna o ID da thread atual
- mysql_list_processes() - Lista os processos MySQL