Page 1 of 1

Connecting to POP3 server/Asynch ops/Modifying content-Yipee

Posted: Sat Jun 22, 2002 11:40 pm
by gxpark
Hi,

I'm currently experimenting with PHP (as some of you may already noticed) by creating a test site.

In that site, I allow users to save their POP3 server settings, so a "sidebar" on every page tells when they have new messages. For this, I'm using UebiMiau's POP3 module.

Now, the question is, How can I count the messages in a POP3 account without stopping the page from rendering? I mean, I have a function to count messages in any account, but while the server is connecting and retrieving the message list, the page stops loading for a while, until the operation is complete.

The question could be rephrased to: How can I take that action asynchronously? Or, how can I take that action AFTER the whole page is loaded, and then put the result somewhere in the middle of the already loaded content.

That sounds rather difficult, but I hope it's not :) Well, for starters I hope it is possible :lol:

Thanks in advance.

Posted: Sun Jun 23, 2002 1:12 am
by will
someone previously asked about printing results from a loop before the loop actually finishes... and as far as i know no one was able to figure anything out. i believe you may be running into the same limition, here's my theory...


<theory only... contains no verified factual information>
being that PHP is a server-sided scripting language, i believe that apache (or whatever web server), waits until all of the script is complete before sending the result back to the visitor... whenever you see a page loading progressively, it is due to bandwidth limitation on your end, the server's end, or somewhere in between... but the server has served up the entire page (or however large of a chunk it sends at a time).... basically, it has already responded to your request. but, like i said, i don't think the server sends back any kind of response until all of the server-side scripting is complete. in other words, there is no way around it without somehow tweaking your server... but PHP has nothing to do with it.
</theory>

anyone care to verify or refute that? maybe feedback on if the same seems to hold true for other server-side languages?

Posted: Sun Jun 23, 2002 10:50 am
by gxpark
I also thought that, but no, Apache sends the script as it is being read. Proof is that if I comment the code that creates the delay, the page is loaded instantaneously (being that the server is in my PC :)), but when the code is uncommented, I see the page parcially, then a delay, and then the whole page.

Anyway, I think I may have found the solution... Stay tuned :wink:

Eureka! as in Yipee!

Posted: Sun Jun 23, 2002 12:23 pm
by gxpark
1. Load the whole page and put a text input control with no border where the messages count is supposed to be. Initial value would be "Searching for new messages".
2. Count the messages in the POP3 server at the very end of the page.
3. Change the value of the previous text input control to reflect the number of messages found (with client-side vbs/js).

Now what I want is to change the value of certain text, not a control, so I can easily format the text (not the case when using a text box). Is it possible to give a name to a certain section of the HTML and later change its contents?

Posted: Sun Jun 23, 2002 5:22 pm
by gxpark
I've found the solution, naming the element and using the innerText property. Nice.

Posted: Sun Jun 30, 2002 11:17 pm
by FireyIce01
you could also write a bit of DHTML... make a <div> and give it an ID, then once you get the message count, you can use a bit of Javascript to access the DIV tag, and write whatever you want into the tag with a document.write, without overwriting the whole page.