How to keep a dynamic webpage dynamic ...
Posted: Fri Jul 05, 2002 6:53 am
How to keep a dynamic webpage dynamic ...
Hi everybody.
Can someone help me with this big problem that I have. Me and my friend is trying to make a community in PHP / mySQL. On the site we have a “friends list” that is going to be updated so the person sees if a friend is online. We can easily solve this by updating the site every, say 30 second but this is not so smart. So we thought that we could make a PHP script that checked with the mySQL-database all the time and updated the page only when it is necessary. That will say when a friend in his or hers list go online.
But now we have 2 problems:
1) If just make a loop that searches for someone to go online in the mySQL-database the site will never stop loading. And if you as an user at the site presses “F5” or refresh you start a new session of PHP and we end up with 20 PHP sessions in the “Task Manager” in Windows 2000 that we are using.
2) The other problem is almost told in the first problem, and it’s the problem that occurs when the user refreshes the page. We end up with over 20 sessions of PHP.exe in the “Task Manager” in Windows 2000 and the server almost crashes. And we have tested “Exit;” but it doesn’t work when the script isn’t finished and the user refreshes the page. And one more thing is that explorer has an one timeout at 5 minute, so we hade to update and load the same page every 4 minute so Internet Explorer didn’t timeout our script.
This is what we written so far and it doesn’t work:
<?php
session_start();
$test = "strang";
print ("HTTP/1.1 200 OK\nContent-Type: multipart/x-mixed-replace;boundary=$test\n\n");
print("--$test");
set_time_limit(0);
ignore_user_abort(1);
$tid = time();
if(session_is_registered('check'))
{
exit;
}
else
{
session_register('check');
}
while(1)
{
if(time() - $tid > 240)
{
break;
}
print("--$test");
sleep(1);
}
?>
<?php header("Location: check.php");?>
Please help US!
//Bezze

Hi everybody.
Can someone help me with this big problem that I have. Me and my friend is trying to make a community in PHP / mySQL. On the site we have a “friends list” that is going to be updated so the person sees if a friend is online. We can easily solve this by updating the site every, say 30 second but this is not so smart. So we thought that we could make a PHP script that checked with the mySQL-database all the time and updated the page only when it is necessary. That will say when a friend in his or hers list go online.
But now we have 2 problems:
1) If just make a loop that searches for someone to go online in the mySQL-database the site will never stop loading. And if you as an user at the site presses “F5” or refresh you start a new session of PHP and we end up with 20 PHP sessions in the “Task Manager” in Windows 2000 that we are using.
2) The other problem is almost told in the first problem, and it’s the problem that occurs when the user refreshes the page. We end up with over 20 sessions of PHP.exe in the “Task Manager” in Windows 2000 and the server almost crashes. And we have tested “Exit;” but it doesn’t work when the script isn’t finished and the user refreshes the page. And one more thing is that explorer has an one timeout at 5 minute, so we hade to update and load the same page every 4 minute so Internet Explorer didn’t timeout our script.
This is what we written so far and it doesn’t work:
<?php
session_start();
$test = "strang";
print ("HTTP/1.1 200 OK\nContent-Type: multipart/x-mixed-replace;boundary=$test\n\n");
print("--$test");
set_time_limit(0);
ignore_user_abort(1);
$tid = time();
if(session_is_registered('check'))
{
exit;
}
else
{
session_register('check');
}
while(1)
{
if(time() - $tid > 240)
{
break;
}
print("--$test");
sleep(1);
}
?>
<?php header("Location: check.php");?>
Please help US!
//Bezze