PHP 中的 connection_status() 函数

programmingserver side programmingphp

connection_status() 函数返回连接状态。

语法

connection_status()

参数

  • NA

返回

connection_status() 函数返回以下可能的值。这是状态位字段 −

  • 0 - CONNECTION_NORMAL - 连接正常运行

  • 1 - CONNECTION_ABORTED - 连接因用户或网络错误而中止

  • 2 - CONNECTION_TIMEOUT - 连接超时

  • 3 - CONNECTION_ABORTED & CONNECTION_TIMEOUT

示例

以下是示例 −

<?php
   switch (connection_status()) {
      case CONNECTION_NORMAL:
         $msg = 'Connection is in a normal state!';
         break;
      case CONNECTION_ABORTED:
         $msg = 'Connection aborted!';
         break;
      case CONNECTION_TIMEOUT:
         $msg = 'Connection timed out!';
         break;
      case (CONNECTION_ABORTED & CONNECTION_TIMEOUT):
         $msg = 'Connection aborted and timed out!';
         break;
      default:
         $msg = 'Status is unknown!';
         break;
   }
   echo $msg;
?>

相关文章