我正在开发一个使用imap连接到某个outlook / Hotmail邮箱的Laravel-5.4应用程序。我不时(约30%)在尝试连接时遇到此错误:
#!/bin/sh
##
## Nexus Miner script
##
NC='\033[31;0m'
RED='\033[0;31;1m'
PUR='\033[0;35;1m'
YEL='\033[0;33;1m'
GRA='\033[0;37;1m'
ADDR="<wallet-address-goes-here"
NAME="<worker-name-goes-here>"
URL="nexusminingpool.com"
## check if user is root, if true, then exit with status 1, else run program.
if [ `whoami` = root ]; then
echo -e "\n${PUR}You don't need ROOT for this!${NC}\n" 1>&2
exit 1;
## running Nexus Miner with Screen so you can run it in background
## and call it up at any time to check mining progress of Nexus CPU Miner.
else
echo -e "\n\n${YEL}Normal User?${NC} ${GRA}[OK]${NC}\n${GRA}Session running with${NC} ${RED}SCREEN${NC}${GRA}, Press${NC} ${RED}^C + A${NC} ${GRA}then${NC} ${RED}^C + D${NC} ${GRA}to run in background.${NC}\n${GRA}to resume enter `${NC}${RED}screen -r${NC}${GRA}` from Terminal.${NC}\n\n"
echo -e "${PUR}Nexus CPU Miner${NC}\n${GRA}Wallet Address:${NC} $ADDR\n${GRA}Worker Name:${NC} $NAME\n${GRA}CPU Threads:${NC} (Default: 2)\n\n"
## call strings for wallet address and worker name varibles followe by thread numbers (default: 2)
## run nexus cpu miner within screen so it can run in the background
`screen /home/user/PrimePoolMiner/nexus_cpuminer $URL 9549 $ADDR $NAME 2`
fi
注意:imapPath和用户名和密码是硬编码的,因此它们在每个请求中保持不变。
try_catch无法捕获错误,因此会阻止我的整个请求。
我得到的错误是:
try {
$imap_open = imap_open($this->imapPath . $this->folder, $this->username, $this->password, OP_READONLY) or die('Cannot connect to : ' . $this->imapPath . ' ' . imap_last_error());
} catch (\Exception $e) {
$output = new ConsoleOutput();
$output->writeln('Imap Connect Exception : ' . $e->getMessage());
}
我想要的是捕获此异常或错误,如果可能的话,我可以在连接断开时再次重新连接到邮箱。