PHP connection_status() 函数

定义和用法

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

可返回的可能值:

  • 0 - CONNECTION_NORMAL - 连接运行正常
  • 1 - CONNECTION_ABORTED - 连接由用户或网络错误终止
  • 2 - CONNECTION_TIMEOUT - 连接超时
  • 3 - CONNECTION_ABORTED & CONNECTION_TIMEOUT

语法

  1. connection_status()

例子

  1. <?php
  2.  
  3. switch (connection_status())
  4. {
  5. case CONNECTION_NORMAL:
  6. $txt = 'Connection is in a normal state';
  7. break;
  8. case CONNECTION_ABORTED:
  9. $txt = 'Connection aborted';
  10. break;
  11. case CONNECTION_TIMEOUT:
  12. $txt = 'Connection timed out';
  13. break;
  14. case (CONNECTION_ABORTED & CONNECTION_TIMEOUT):
  15. $txt = 'Connection aborted and timed out';
  16. break;
  17. default:
  18. $txt = 'Unknown';
  19. break;
  20. }
  21.  
  22. echo $txt;
  23. ?>