Php, IMAP logout how to?
didn't find any solution in previous questions. I've developed a simple imap access to my server, it's working well, but I've a big problem.
Server is running slow and is getting down due to open imap sessions.
How do I close / logout? In the php imap documentation I don't find a solution, I use this
function correio ($caixa) {
if($caixa ==="Inbox") {
if($_REQUEST['user'] == "Gmail") {
$box = imap_open(servidor."INBOX", user, pass) or die (imap_last_error());
$informacoes = imap_status($box, servidor.$caixa, SA_ALL);
} else {
$box = imap_open(servidor, user, pass) or die (imap_last_error());
$informacoes = imap_status($box, servidor.".".$caixa, SA_ALL);
}
} else {
if($_REQUEST['user'] == "Gmail") {
$box = imap_open(servidor."[Gmail]/".$caixa, user, pass) or die (imap_last_error());
$informacoes = imap_status($box, servidor."[Gmail]/".$caixa, SA_ALL);
} else {
$box = imap_open(servidor.".".$caixa, user, pass) or die (imap_last_error());
$informacoes = imap_status($box, servidor.".".$caixa, SA_ALL);
}
}
if($box) {
$n = imap_check($box);
$conteudos = imap_fetch_overview($box,"1:{$n->Nmsgs}", 0);
$msgs .= "<div id='div_".$caixa."' class='menu'>";
$msgs .= "<h3 id='".$caixa."' class='".$caixa."'>".$caixa." Total: ".$informacoes->messages.", Últimas: ".$informacoes开发者_如何学运维->recent.", Não lidas: ".$informacoes->unseen."</h3>";
$msgs .= "<div class='mensagens'>";
if($conteudos) {
foreach($conteudos as $mensagem) {
$de = imap_mime_header_decode($mensagem->from);
$msgs .= "<h1 class='".$caixa."'><input type='checkbox' id='".$mensagem->uid."' class='in_".$caixa."' /> ".$de[0]->text."
<script type='text/javascript'>
$('input:checkbox').click(function(event) {
event.stopPropagation();
});
</script>
</h1>";
$subject = imap_mime_header_decode($mensagem->subject);
for ($i=0; $i<count($subject); $i++) {
$assunto = $subject[$i]->text;
}
$msgs .= "<p id='msg_".$mensagem->uid."'>".$assunto."
<script type='text/javascript'>
$('#msg_".$mensagem->uid."').click(function() {
ver_mensagem('".$caixa."', '".$mensagem->uid."');
});
</script>
</p>";
}
} else {
$msgs .= "<h1 class='".$caixa."'>Não há mensagens novas.</h1>";
}
$msgs .= "</div>";
$msgs .= "</div>";
return $msgs;
imap_close($box);
} else {
die("Ligação recusada: " . imap_last_error());
imap_close($box);
}
}
if($inbox =& correio("Inbox")) {
$f = $inbox;
if($spam =& correio("Spam")) {
$f .= $spam;
}
}
//echo "f = ".$f."<br />";
$str = "<div id='wrapper'><div id='mobimail' style='display:none'>";
$str .= $f;
$str .= "</div></div>";
$str .= "<div id='footer' class='footer' align='center'>
<div class='todos' align='center'></div>
<div class='apagar' align='center'></div>
<div class='mover' align='center'></div>
<div class='reload' align='center'></div>
<div class='sair' align='center'></div>
</div>";
echo $header."|||".$str;
imap_close($box);
var_dump(imap_close($box));
If the connection is closed, you obviously log out. Closing probably fails, what does imap_close($box)
returns?
What is the return value of imap_close()
? It can be Either True
or False
, there is no guarantee that it will always close the stream.
You can try running a simple test setup: imap_open()
followed by a simple command such as imap_ping()
and then immediate imap_close()
. Does this close the connection as expected or does it stay open?
Also make sure you don't call multiple imap_open()
s before first closing them. Use either imap_reopen()
, call imap_close()
before imap_open()
, or use a different variable to store the connection identifier (But make sure you imap_close()
both of them!).
精彩评论