I made a while loop in php:
<?php
include_once("connect.php");
$search=mysql_query("SELECT * from chat ORDER BY id DESC LIMIT 1");
$row=mysql_fetch_assoc($search);
$type=$row['type'];
$id=$row['id'];
while($type!='n'){
usleep(10000);
$search=mysql_query("SELECT * from chat ORDER BY id DESC LIMIT 1");
$row=mysql_fetch_assoc($search);
$type=$row['type'];
}
$run=mysql_query("UPDATE chat SET type='o' WHERE id=$id");
mysql_close($conn);
echo $row['message'] . "<br/>";
?>
It always runs to see if there are new entries in the database, but I dont know what to do to keep the server from overloading. I tried usleep but I don’t think it’s enough.
Also I am getting this error “Fatal error: Maximum execution time of 60 seconds exceeded” and I know I can change the number of repetitions in the .ini file but would that be wise? Will it have a really bad effect on the servers performance?
You
whileloop never terminates since you always get the last record, but make no changes to it.. so you go in the loop once and always check the same record without ever leaving the loop…You should try to convert your infinite loop to a scheduled event that runs at some interval .. using cron jobs ..
Update
If you are waiting for some other action to change the type of the last record so that this code will catch it and exit the loop, then your algorithm is not fit for client/server applications..
You should predict at some other point the time where the record is ready to be altered and call the code at that time, instead of going to an infinite loop until some external event makes the loop non-infinite..