Php, IMAP logout how to?
<p>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.</p>

<p>Server is running slow and is getting down due to open imap sessions.</p>

<p>How do I close / logout? In the php imap documentation I don't find a solution, I use this</p>

<pre><code>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-&gt;Nmsgs}", 0);
    $msgs .= "&lt;div id='div_".$caixa."' class='menu'&gt;";
        $msgs .= "&lt;h3 id='".$caixa."' class='".$caixa."'&gt;".$caixa."&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Total: ".$informacoes-&gt;messages.", Últimas: ".$informacoes-&gt;recent.", Não lidas: ".$informacoes-&gt;unseen."&lt;/h3&gt;";
        $msgs .= "&lt;div class='mensagens'&gt;";
            if($conteudos) {
                foreach($conteudos as $mensagem) {
                    $de = imap_mime_header_decode($mensagem-&gt;from);
                    $msgs .= "&lt;h1 class='".$caixa."'&gt;&lt;input type='checkbox' id='".$mensagem-&gt;uid."' class='in_".$caixa."' /&gt;&amp;nbsp;&amp;nbsp;".$de[0]-&gt;text."
                    &lt;script type='text/javascript'&gt;
                        $('input:checkbox').click(function(event) {
                            event.stopPropagation();
                        });
                    &lt;/script&gt;   
                    &lt;/h1&gt;";
                    $subject = imap_mime_header_decode($mensagem-&gt;subject);
                    for ($i=0; $i&lt;count($subject); $i++) {
                        $assunto = $subject[$i]-&gt;text;
                    }
                    $msgs .= "&lt;p id='msg_".$mensagem-&gt;uid."'&gt;".$assunto."
                                &lt;script type='text/javascript'&gt;
                                    $('#msg_".$mensagem-&gt;uid."').click(function() {
                                        ver_mensagem('".$caixa."', '".$mensagem-&gt;uid."');
                                    });
                            &lt;/script&gt;
                          &lt;/p&gt;";
                }
            } else {
                $msgs .= "&lt;h1 class='".$caixa."'&gt;Não há mensagens novas.&lt;/h1&gt;";
            }
        $msgs .= "&lt;/div&gt;";
    $msgs .= "&lt;/div&gt;";
    return $msgs;
    imap_close($box);
} else {
    die("Ligação recusada: " . imap_last_error());
    imap_close($box);
}
}

if($inbox =&amp; correio("Inbox")) {
    $f = $inbox;
    if($spam =&amp; correio("Spam")) {
        $f .= $spam;
    }
}
//echo "f = ".$f."&lt;br /&gt;";
$str = "&lt;div id='wrapper'&gt;&lt;div id='mobimail' style='display:none'&gt;";
$str .= $f;
$str .= "&lt;/div&gt;&lt;/div&gt;";
$str .= "&lt;div id='footer' class='footer' align='center'&gt;
&lt;div class='todos' align='center'&gt;&lt;/div&gt;
&lt;div class='apagar' align='center'&gt;&lt;/div&gt;
&lt;div class='mover' align='center'&gt;&lt;/div&gt;
&lt;div class='reload' align='center'&gt;&lt;/div&gt;
&lt;div class='sair' align='center'&gt;&lt;/div&gt;
&lt;/div&gt;";
echo $header."|||".$str;
imap_close($box);
var_dump(imap_close($box));
</code></pre>
