Função connection_status() do PHP

Definição e Uso

A função connection_status() retorna o estado atual da conexão.

Possíveis valores que podem ser retornados:

  • 0 - CONNECTION_NORMAL - Conexão está funcionando normalmente
  • 1 - CONNECTION_ABORTED - Conexão foi encerrada por erro do usuário ou da rede
  • 2 - CONNECTION_TIMEOUT - Conexão expirou o tempo
  • 3 - CONNECTION_ABORTED & CONNECTION_TIMEOUT

Sintaxe

connection_status()

Exemplo

<?php
switch (connection_status())
{
case CONNECTION_NORMAL:
   $txt = 'Conexão está em um estado normal';
   break;
case CONNECTION_ABORTED:
   $txt = 'Conexão abortada';
   break;
case CONNECTION_TIMEOUT:
   $txt = 'Conexão expirou o tempo';
   break;
case (CONNECTION_ABORTED & CONNECTION_TIMEOUT):
   $txt = 'Conexão abortada e expirou o tempo';
   break;
default:
   $txt = 'Unknown';
   break;
}
echo $txt;
?>