Page 1 of 1

periodic (automatic) function calls

Posted: Sat Nov 11, 2006 5:03 pm
by sa177ir
Is there a way with PHP to automatically call a function every x seconds and have it perform some functionality?

For a group project, we are developing a web-app that has a graph. The graph needs to be updated every x seconds automatically. Is there an elegant way to do this?

A hack way I can think of is calling a function and running it with WHILE(1) and having it sleep for x seconds and then perform some functionality. I'm sure this is terrible as it will waste unnecessary resources spinning.

Any help would be appreciated it...thanks

Posted: Sat Nov 11, 2006 5:07 pm
by John Cartwright
search "cron job" or "task scheduler" for windows

Posted: Sat Nov 11, 2006 5:08 pm
by timvw
Why do you want to update itself every x time? Whenever it's requested, make it check how old it is, and then decided to perform the update or not...

Anyway, you might want to search the web for 'cron or crontab' too...

Posted: Sat Nov 11, 2006 5:17 pm
by aaronhall
Are you wanting to update the graph and then push the new graph to the browser? Aside from flash or JS, you could use a meta-refresh tag to reload the update script ever couple of seconds.

Posted: Sat Nov 11, 2006 5:49 pm
by Ambush Commander
You'll probably want to use AJAX.