periodic (automatic) function calls

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!

Moderator: General Moderators

Post Reply
sa177ir
Forum Newbie
Posts: 4
Joined: Sat Nov 11, 2006 5:00 pm

periodic (automatic) function calls

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

search "cron job" or "task scheduler" for windows
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

You'll probably want to use AJAX.
Post Reply