By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

fsock problem - please help!

P: n/a
Hi,

Im having a problem with an (apparently) simple little script, which is
designed to log on to a POP3 server and list the number of emails. I can log
in with username and password, and can relay the server echos back to the
page, but run into problems when I attempt to set up a while loop to read
more than one line of repsonse from the server.

My code looks like this:
fputs ($server_connect, "LIST \n\n");

while (!feof($server_connect)) {
echo fgets ($server_connect,255);
echo "<br>";
}
fclose ($server_connect);
$server_connect is an instance of the fsockopen() function. I keep getting
the appropirate output from this code, but only once the page has timed out!

Does anyone know how I could go about fixing this, so that I capture all
output from the server, but dont have to wait for a timeout to see the data.

Thanks.

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Carved in mystic runes upon the very living rock, the last words of
Steve Macleod of comp.lang.php make plain:
Im having a problem with an (apparently) simple little script, which
is designed to log on to a POP3 server and list the number of emails.
I can log in with username and password, and can relay the server
echos back to the page, but run into problems when I attempt to set up
a while loop to read more than one line of repsonse from the server.

My code looks like this:
fputs ($server_connect, "LIST \n\n");
First of all, there should be no space, and only one newline after LIST.
I don't know that the space hurts anything, but it doesn't belong there.
while (!feof($server_connect)) {


The server's responses end with a period by itself on a line. Check for
that instead of eof.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #2

P: n/a
Carved in mystic runes upon the very living rock, the last words of Alan
Little of comp.lang.php make plain:
The server's responses end with a period by itself on a line. Check
for that instead of eof.


Actually, that's inaccurate. Multi-line responses end with a period by
itself. Some responses (to a STAT command, for example) are just one line.
For more info, refer to the POP3 RFC (if you haven't already):

ftp://ftp.rfc-editor.org/in-notes/rfc1939.txt

There's a great example POP session near the end of the document.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #3

P: n/a
Alan Little wrote:
Carved in mystic runes upon the very living rock, the last words of
Steve Macleod of comp.lang.php make plain:

Im having a problem with an (apparently) simple little script, which
is designed to log on to a POP3 server and list the number of emails.
I can log in with username and password, and can relay the server
echos back to the page, but run into problems when I attempt to set up
a while loop to read more than one line of repsonse from the server.

My code looks like this:
fputs ($server_connect, "LIST \n\n");

First of all, there should be no space, and only one newline after LIST.
I don't know that the space hurts anything, but it doesn't belong there.

while (!feof($server_connect)) {

The server's responses end with a period by itself on a line. Check for
that instead of eof.

throw a call to flush() in there after the echos or turn
ob_implicit_flush() on so PHP will send what it has to the browser
instead of waiting for you to end the page.

--
John Downey
http://delusive.dyn.ee
http://sage.dev.box.sk
http://blacksun.box.sk

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.