PHP - imap_timeout() 函式



PHP 的 IMAP 函式幫助您訪問電子郵件帳戶,IMAP 代表 **I**nternet **M**ail **A**ccess **P**rotocol,使用這些函式,您還可以使用 NNTP、POP3 協議和本地郵箱訪問方法。

imap_timeout() 函式接受一個表示超時型別的整數作為引數,並設定/獲取超時。

語法

imap_timeout($timeout_type, $timeout);

引數

序號 引數及描述
1

timeout_type (必填)

這是一個整數,表示超時型別,可以是以下之一:

  • IMAP_OPENTIMEOUT

  • IMAP_READTIMEOUT

  • IMAP_WRITETIMEOUT

  • IMAP_CLOSETIMEOUT

2

timeout (可選)

這是一個整數,表示超時值(秒)。

返回值

此函式返回一個布林值,成功時為 TRUE,失敗時為 FALSE。

PHP 版本

此函式首次引入於 PHP 4 版本,並在所有後續版本中可用。

示例

以下示例演示了 imap_timeout() 函式的用法:

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
         print("The current read timeout is ");
         
         $time_out = imap_timeout(IMAP_READTIMEOUT);
         print($time_out);
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
The current read timeout is 60

示例

您可以手動設定超時秒數,如下所示:

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
         print("The current read timeout is ");
         $time = 25;
         $time_out = imap_timeout(IMAP_READTIMEOUT, $time);
         print($time_out);
         
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出:

Connection established....
The current read timeout is 1
php_function_reference.htm
廣告