我有一个大型项目,该项目使用多线程并与imap进行交互。问题是当我收到一封大邮件时,CPU使用率会上升到100%。当我添加usleep()时,CPU的使用量减少了对CPU的使用。但是邮件下载需要很多时间!
while ((time() - $time) < $this->timeOut) {
$newLine = fread($this->stream, 2048*8);
if(!strlen($newLine)) continue;
$buf .= $newLine;
file_put_contents(__DIR__ . "/MAIL.txt", $newLine, FILE_APPEND);
if (strripos($buf, $successPattern) !== FALSE){
$this->responseContainer->setLastResponseText($buf);
return $buf;
}
if (strripos($buf, $this->commandHash . ($this->commandCounter - 1) . ' NO') !== FALSE
|| strripos($buf, $this->commandHash . ($this->commandCounter - 1) . ' BAD') !== FALSE){
$this->responseContainer->setLastErrorText($buf);
return false;
}
usleep(50000);
}