howto: schedule a call to a php-page every 5 seconds

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
flummi
Forum Newbie
Posts: 1
Joined: Fri Aug 08, 2003 6:19 am

howto: schedule a call to a php-page every 5 seconds

Post by flummi »

Hi there, :roll:

I have written a php page to update my database with data from files and i want to have this script to be called every 5 seconds. How can I do this?
Is it possible to schedule this call on the server? And how?
I do have full root access to the server so I should have all possiblilities to do this.

Thanx for any help,
Flummi
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

check out sleep() function
=---------show.php
...
.
..
.
sleep(4);
header("Location:show.php");
=--------------------
give the same page name in location header
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

If you're on a *nix machine use cron.
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

Post by tylerdurden »

Isn't the min interval for cron 1 min? ;-)
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Oops, true.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Important question: Why would you want something run every 5 seconds? Why not just run the program, and let it run. And then let the program operate every 5 seconds?

It would be better if you explained what you are trying to do, rather than have us try to help you put together a solution that may be the wrong solution.

Example of why this is bad. You hire someone to build you a table. They build you a table. But what you really needed was 6 chairs. Sure, they can help you build a great table, but it doesn't solve the real problem: that problem being seating.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

...also.

If you got 2 users/h, why update the database making the server work for nothing? Adding an "update table..." in the beginning of the sites backend could help, but if you got 1000's of visits/min, you get high loads.

Workaround could be to increase a value on each visit, and when it hits a certain amout (or a certain time()-(time()-5) has passed, do the update.

Just my 2 cents...
Post Reply