正在显示
1 个修改的文件
包含
19 行增加
和
2 行删除
| @@ -22,6 +22,11 @@ class ImapClient { | @@ -22,6 +22,11 @@ class ImapClient { | ||
| 22 | public int $tagNum = 0; | 22 | public int $tagNum = 0; | 
| 23 | 23 | ||
| 24 | /** | 24 | /** | 
| 25 | + * @var int | ||
| 26 | + */ | ||
| 27 | + public int $timeOut = 3; | ||
| 28 | + | ||
| 29 | + /** | ||
| 25 | * 是否是非阻塞模式 | 30 | * 是否是非阻塞模式 | 
| 26 | * @var bool | 31 | * @var bool | 
| 27 | */ | 32 | */ | 
| @@ -33,6 +38,18 @@ class ImapClient { | @@ -33,6 +38,18 @@ class ImapClient { | ||
| 33 | } | 38 | } | 
| 34 | 39 | ||
| 35 | 40 | ||
| 41 | + /** | ||
| 42 | + * @param int $ttl 秒 | ||
| 43 | + * @return $this | ||
| 44 | + * @author:dc | ||
| 45 | + * @time 2025/3/20 10:52 | ||
| 46 | + */ | ||
| 47 | + public function setTimeOut(int $ttl) | ||
| 48 | + { | ||
| 49 | + $this->timeOut = $ttl; | ||
| 50 | + return $this; | ||
| 51 | + } | ||
| 52 | + | ||
| 36 | 53 | ||
| 37 | public function open(){ | 54 | public function open(){ | 
| 38 | $content = stream_context_create([ | 55 | $content = stream_context_create([ | 
| @@ -96,7 +113,7 @@ class ImapClient { | @@ -96,7 +113,7 @@ class ImapClient { | ||
| 96 | 113 | ||
| 97 | $totalBytes = strlen($cmd); | 114 | $totalBytes = strlen($cmd); | 
| 98 | $bytesWritten = 0; | 115 | $bytesWritten = 0; | 
| 99 | - $maxW = 50; | 116 | + $maxW = $this->timeOut*10; | 
| 100 | while ($bytesWritten < $totalBytes) { | 117 | while ($bytesWritten < $totalBytes) { | 
| 101 | $result = fwrite($this->socket, substr($cmd, $bytesWritten)); | 118 | $result = fwrite($this->socket, substr($cmd, $bytesWritten)); | 
| 102 | // 写失败了 | 119 | // 写失败了 | 
| @@ -131,7 +148,7 @@ class ImapClient { | @@ -131,7 +148,7 @@ class ImapClient { | ||
| 131 | * @time 2024/9/13 15:49 | 148 | * @time 2024/9/13 15:49 | 
| 132 | */ | 149 | */ | 
| 133 | protected function readLine(){ | 150 | protected function readLine(){ | 
| 134 | - $i = 50; // 非阻塞模式下,只等待5秒,没返回数据就返回 | 151 | + $i = $this->timeOut*10; // 非阻塞模式下,只等待5秒,没返回数据就返回 | 
| 135 | $str = false; | 152 | $str = false; | 
| 136 | while ($i>0){ | 153 | while ($i>0){ | 
| 137 | $str = fgets($this->socket,2048); | 154 | $str = fgets($this->socket,2048); | 
- 
请 注册 或 登录 后发表评论