scheduling a php page to run every hour....

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

User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

scheduling a php page to run every hour....

Post by Burrito »

I just created a report that I need to have run every hour. My plan was to use the windows task scheduler and just the PHP CLI, but I just found out as I was trying to schedule my task that the smallest increments I can do are days (windows 2000 server).

I've heard the term cron job tossed around in here a lot but I've always just associated that with *nix. Is it something that can be done with windows? If not is there some other alternative that I can do to schedule a php page to be run every hour?

please advise.

thx,

Burr
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

too lazy to lookup win2k scheduling features..... but in the end you could have 24 tasks (one for each hour).. and issue would be solved too ;)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

ugghh...I suppose I could do that...but isn't there a better way?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

could you not have a browser running and then use javascipt to submit the page once an hour to run what ever page you need to run.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

well I'd rather not have to leave someone logged in to the server with a browser window open.

Isn't there some kind of cron for windows?

I'm pretty sure I've heard of it...the other alternative we've thought of would be to just install automate on there to do it...but wanna avoid that if possible.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

I found this...

http://www.kalab.com/freeware/cron/cron.htm

gonna give it a looksy
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

cron jobs are exactly what you need to use. you should, however, be able to do it in windows server 2000 as well.. i was able to before i moved on to 2k3 enterprise
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

infolock wrote:cron jobs are exactly what you need to use. you should, however, be able to do it in windows server 2000 as well.. i was able to before i moved on to 2k3 enterprise
you were able to do it with the task scheduler you mean?

if so, by the hour???

or with cron jobs?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

mainly at midnight every day. it mainly just ran my backup of a media server log file every night and then executed another php script to generate the reports.

edit: sorry i misunderstood your original question. let me reitterate :

yes, for a one time thing, task scheduler. but it also has options to run hourly (http://support.microsoft.com/?kbid=226795)

yes for a hourly run, cron jobs.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

You can run them in smaller increments than hours/days.

Modifying a Scheduled Task
1. Click Start, point to Settings, and then click Control Panel.
2. Double-click Scheduled Tasks.
3. Right-click the task you want to modify, and then click Properties. If no task is listed, double-click Add Scheduled Task to start the Scheduled Task Wizard.

NOTE: If you use the Scheduled Task Wizard, click the Open advanced properties for this task when I click Finish check box select it, and then click Finish to continue.
4. Click the Schedule tab, and then click Advanced.
5. Click the Repeat task check box to select it, and then specify the number of minutes or hours you want the task to be repeated.
6. Click OK, and then click OK again.
See the link infolock posted for more details.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

doh! You're right.

/me feels like an ass.

thx
windforceus
Forum Newbie
Posts: 23
Joined: Tue Mar 15, 2005 12:40 pm

questions

Post by windforceus »

ah, i want to use cron but i am a newbie, can someone give a better tutorial?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

the link I posted above (http://www.kalab.com/freeware/cron/cron.htm) has some pretty good examples of how to do it.

that's what I ended up using and it works fine...wish I'd have known about the windows task mgr thingy sooner 8O
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Sami, I am having to do this again (on another system) and so I figured I'd try using the task scheduler built into windows (using your suggestion), and I am running into an issue.

I have the repeat task check box checked and selected every: 1 hours. when I click ok, it tells me that the duration must be LONGER than the repitition interval. That seems counterintuitive to me. It won't let me "save" it unless I make the duration 1:01 or greater. This doesn't make sense to me, wouldn't that make the duration of the task overlap the next scheduled task? It would make sense to me if the duration had to be LESS, but not more.

If someone could explain the logic behind this, I'd really appreciate it.

ty,

Burrito
spsellars
Forum Newbie
Posts: 1
Joined: Sun Apr 10, 2005 12:48 am

Why not use the AT command?

Post by spsellars »

I say dump the GUI Task Scheduler and use the AT command in a command prompt. (Assuming your script can be run as local service.)

Copy the following at commands to file called schedule.bat (or whatever you want), obviously change the script and php location to match your setup, and run the batch file from a command prompt. After that your script should run on the hour every hour. (Make changes to the time as necessary too.) This is what I use to schedule updates for clients on my network, much easier this way. One thing you may want to look into is Priado Blender (spelling?), it's free and bundles your script into an exe with the php interpreter, I usually do that for my scheduled php scripts as I change my web server php version every time a new version comes out, and that can lead to surprises in your scheduled scripts.


----------- Copy everything BELOW this line to .bat file --------------
at 0:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 1:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 2:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 3:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 4:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 5:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 6:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 7:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 8:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 9:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 10:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 11:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 12:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 13:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 14:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 15:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 16:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 17:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 18:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 19:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 20:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 21:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 22:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
at 23:00 /EVERY:M,T,W,Th,F,S,Su "c:\php\php.exe c:\mydir\myscript.php"
Post Reply