Problem with fputs/fgets
| From: | Jason Young | Date: | Wed, 16 Oct 2002 21:02:06 +0000 |
| Subject: | Problem with fputs/fgets | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-120239@lists.php.net to get a copy of this message | ||
I'm in the process of writing a very very simple web-based email client, just for my personal use, so I can perm-delete all the spam that comes in through the day on my home account before i get home.
On the very first connect, its great.. connects, does a 'uidl' which lists all the mail ID's (the 'else' part of the if statement below)
The problem lies where I click the generated link and attempt to read a message, the browser load just hangs (despite the set_time_limit()) and when I cancel it, the server tells me there's another connection active.
I have an fputs($pop, "QUIT\r\n); as well as an fclose($pop); .. Shouldn't this be sufficient to make sure the connection is closed before my visit to trying to read a message? Or is that not the problem?
I'm thinking its something with the actual ($action == "read") code.. but... what would it be?
Thanks for all help!
-Jason
Code----
<?
if (isset($_GET['action']))
$action = $_GET['action'];
if (isset($_GET['msg']))
$msg = $_GET['msg'];
$pop = fsockopen("pop.server", 110, $errno, $errstr, 300);
fgets($pop,255);
fputs($pop,"USER name\r\n");
fgets($pop,255);
fputs($pop,"PASS word\r\n");
$status = fgets($pop,255);
if (substr($status, 0, 4) == "-ERR") {
echo $status;
exit();
}
if ($action == "read") {
set_time_limit(10);
$cmd = "top $msg 10";
fputs($pop, $cmd);
$themsg = fgets($pop);
echo $themsg;
} else {
fputs($pop,"uidl\r\n"); // Get list of messages
$list = fgets($pop,255)."<br>";
$list = substr($list, 4, strpos($list, " ", 3));
for ($i = 1; $i <= $list; $i++) {
$curr = fgets($pop);
echo "<a href=\"?action=read&msg=".substr($curr, 0, strpos($curr, " "))."\">$curr</a><br>";
}
echo "<br>$list messages";
}
fputs($pop,"QUIT\r\n");
echo fgets($pop);
fclose($pop);
?>