2016-02-19 152 views
-1

有沒有辦法跟蹤imap_open()的實時連接時間?我試過imap_timeout(),但它只需要在php.ini中設置超時。我想在這裏實現的是檢查連接錯誤之前需要多長時間(類似於錯誤的用戶名)。IMAP連接跟蹤

$mbox = imap_open($this->data['ServerName'], $this->data['UserName'], $this->data['PassWord']); 
    $time = time(); 
    // $mbox = imap_open("{}INBOX", "", ""); 

    $x = imap_timeout(IMAP_OPENTIMEOUT); 
      echo "<pre>"; 
      var_dump($x); 
      echo "</pre>"; 
    var_dump(time() - $time); 
    if ($hdr = imap_check($mbox)) { 
     echo "Num Messages: " . $hdr->Nmsgs ."\n\n<br><br>"; 

     return $mbox; 
    } else { 
     // error_log("Connection Failed. Could not Connect to the Mail Server", 0); 
     // $this->sendErrorMail("Connection Failed. Could not Connect to the Mail Server"); 
     die("Connection Failed. Could not Connect to the Mail Server"); 
    } 

回答

0

imap_timeout帶參數。你想要的是常量IMAP_OPENTIMEOUT。

echo imap_timeout(IMAP_OPENTIMEOUT);

+0

我已經試過了。我更新了上面的代碼,但它仍然返回60秒,並且我還顯示了連接發生錯誤之前的確切時間,它不一樣。 – janers2014