ch2450: I'm viewing the page in Safari 3.1.2 and before I closed the
window I reached over 100 reloads. The file displayPosts.php is being
loaded over and over, stacking on top of others and filling up memory.
I've had problems with the setInterval() function myself doing some
animations, and I've found that recursive functions are cleaner and
faster. Try this: rather than having the page just reload every 2
seconds, why not attach an event to your "Submit" button for each
client's chat window, this event will make an ajax call to a PHP page
which will in turn open a mySQL connection and set a variable "flag"
which could be in the table where all your messages are kept. The flag
could act as a switch, when someone submits a message the flag is set
to true, then on the other persons machine when they read the message
the flag is set back to false. Now the triggers on each machine to
check for messages could possibly work like this: open a persistent
connection to your sql DB, and write a seperate function which will
call up a random number between 1 and 1000. Then say "if the number is
> 900" then examine the flag variable in the DB to see if it's set to
true, if so read the entry posted by the other client and set the flag
to "false" because it's been read. Have the function call itself at
the end of either scenario, true or false on the flag, as well as if
the random number is < 900. I have no idea if this will work I haven't
tried it but I'm interested to see if it does! Good luck!

Reply via email to