Controllare lo stato della connessione in PHP
Dalla versione 4 di PHP esiste una funzione per il controllo della connessione: connection_status!
Questa funzione ritorna un valore intero, che può assumere questi significati:
- 0 - CONNECTION_NORMAL
- 1 - CONNECTION_ABORTED
- 2 - CONNECTION_TIMEOUT
- 3 - CONNECTION_ABORTED & CONNECTION_TIMEOUT
Per fare qualche test, possiamo usare un codice del genere:
switch (connection_status()) {
case CONNECTION_NORMAL:
$txt = 'Connection is in a normal state';
break;
case CONNECTION_ABORTED:
$txt = 'Connection aborted';
break;
case CONNECTION_TIMEOUT:
$txt = 'Connection timed out';
break;
case (CONNECTION_ABORTED & CONNECTION_TIMEOUT):
$txt = 'Connection aborted and timed out';
break;
default:
$txt = 'Unknown';
break;
}
echo $txt;
Enjoy!
php connection connection_status
Commentami!