PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Is it possible to make a script check for a value in a database every x seconds, and then proceed with the script once it has been found? I have tried putting this at the end of the script:
Echo "Page content here";
$num = 0;
while ( $num == 0 ) {
sleep(5);
$query="select * from messages where recipient='$username'";
$result=mysql_query($query);
$num=mysql_numrows($result);
}
header("Location: messages.php");
I thought this would display the contents of the page until the query in the while loop returned a result, then the while loop would break and the header() command would be executed, but the page remained blank until the while loop completed, at which point the header() command executed. The problem is that none of the contents of the page is displayed.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi feyd, thanks very much for your quick response! I put the flush() command before the start of the while loop, and it did indeed "flush" all the output up to that point in to the browser. I then simulated the user receiving a message by inserting a record in to the messages table, and the script continued!
The problem is that after 30 seconds the script times out because the max execution time of 30 seconds is exceeded. I tried increasing this in the php config file then stopping and restarting Apache, but it still times out after 30 seconds. Is there somewhere else I need to change this? Or can I not increase it to more than 30 seconds?