# continous task

**URL:** <https://forums.percona.com/t/continous-task/573>\
**Category:** Other MySQL® Questions\
**Created:** [December 20, 2007, 7:22am UTC](https://forums.percona.com/t/continous-task/573 "2007-12-20T07:22:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leinad](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@Leinad](https://forums.percona.com/u/Leinad)\
**Post date:** [December 20, 2007, 7:22am UTC](https://forums.percona.com/t/continous-task/573/1 "2007-12-20T07:22:12Z")

</div>

Ok, I’m stuck again 😕

I have 2 problems now (one lies withing mysql, and the other I just hope you know the answer :o )

a continuous task is the main one…

how do I create one?? and how do create an efficient one (mysql talkin’)

I tried with this

```
while(1){ $starttime=time(); //your cron actions here //select all the ended builts $sql="SELECT * FROM twwbuilds WHERE endtime<$starttime"; $query=mysql_query($sql); $rows=mysql_num_rows($query); if($rows!=0) { $rs=mysql_fetch_assoc($query); do { $buildid=$rs["buildid"]; $sql="DELETE FROM twwbuilds WHERE buildid=$buildid";//much more code goes here, like updating the level of the building and stuff //besides building are not the only thing that need continuos checkin'...attacks and marketplace needs it too $query2=mysql_query($sql); }while($rs=mysql_fetch_assoc($query)); } sleep(5);	}</pre>

```

I open the page and the task executes well as long as I keep the page open (YET here’s one of my questions…it’s efficient to do it this way??) when I close the page the task executes for like 1 minute then stops…how do I prevent this??

I REALLY need to continualy check if a building is over and the only way I have found is this continuos task.

or if you have a better way please tell me 😕 my head-aches already ( :o
