Connecting Tech Pros Worldwide Forums | Help | Site Map

Execute script every 10 seconds for ten minutes

Newbie
 
Join Date: Dec 2007
Posts: 27
#1: Jul 19 '08
i want to execute a script for every 10 seconds . and the loop is 10 minutes long.
I written the code like this but i got timeout warning. i have changed the execution time too in .ini file. please tell me what is wrong or give me a sample code for this:

[PHP]$time = time();
$timeafter10mins = $time+10*60;
$result = mysql_query("select * from tbl_outbox where UniqueID like '%12345%'");
while($time < $timeafter10mins)
{
while($row = mysql_fetch_array($result))
{
$uniqueid = $row['UniqueID'];
$text = $row['message'];
$from = $row['From_Mobile_number'];
$dated = $row['dated'];
}
if($text!="" && stristr($text,$uniqueid))
{
$data = "<?xml version='1.0' ?>
<SMS NO='$from'><SMStext>".$text."</SMStext><SMStime>".$dated."</SMStime></SMS>";
$fh = fopen($uniqueid.'.xml', 'w');
fwrite($fh, $data);
$xmlfile = $uniqueid.'.xml'
?>
<script>window.location.href='<?=$xmlfile?>';</script><?
exit();
}
$time = $time + 10;
sleep($time);
[/PHP]
Please give me a solution. Waiting for your response,
Thanks in advance,
Sridevi.
}

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Jul 19 '08

re: Execute script every 10 seconds for ten minutes


You'd be better off using a meta refresh tag to reload the page every ten seconds or using JavaScript to make an XMLHttpRequest (Ajax).

Please use code tags when posting code and remember to use a good thread title.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 914
#3: Jul 22 '08

re: Execute script every 10 seconds for ten minutes


Or use Cron Jobs provided your server has their capabilities.
Reply


Similar PHP bytes