Okay, so I'm playing with an idea for my chat system. I want to offer an option of a 'streaming' style where the window stays alive and displays the messages automatically when one is received.
I know that AJAX or json would be a better and more server-friendly way of doing this but quite frankly, I know about as much javascript and json just to get me by and I wouldn't know where to begin to take it to the level that I'm needing.
Therefore. . .I'm playing with flush and sleep for the time being. I have everything worked out except for the most important part: show the messages! lol
Here is the snippet of code in question:
if (ob_get_level() == 0) ob_start();
$row = mysql_fetch_array($outres);
for ($i = 0; $i<10; $i++){
echo '<!-- bufferme -->';
echo str_pad('',4096)."\n";
ob_flush();
flush();
sleep(10);
}
output_message($row);
} else {
// This will be some message for when the 'stream' dies with a 'reconnect' button
}
What I'm getting right now is the -- bufferme -- every 10 seconds and then when the count of 10 (as set in the "for" area) is over, THEN it prints whatever messages were received.
I had it setup a bit different before but what it did then was to print the same message over and over until that count of 10 was over.
What am I missing here? Oh, and I hope I'm making sense and people are able to follow what I'm trying to explain! 😃