homepage Welcome to WebmasterWorld Guest from 54.145.252.85
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Cronjob
need to automate a few simple functions
freshfish

10+ Year Member



 
Msg#: 10388 posted 10:31 pm on Oct 5, 2005 (gmt 0)

Hey there,
I have a serious of tasks that my script does
...task1.php
...task2.php
...task3.php

and I need to run them every hour at night while sleeping. How can I create a simple script that would allow me to do this?

Thanks in advance :)

 

chrisjoha

5+ Year Member



 
Msg#: 10388 posted 10:38 pm on Oct 5, 2005 (gmt 0)

Sure can! :) If you're on windows, do this: Make a bat file where you put:

cd <dir where scripts are>
php task1.php
php task2.php
php task3.php

and save the file as tasks.bat. Now you add a scheduled task by going to Start->All programs->Accessories->System tools->Scheduled tasks

Click add scheduled task and follow the rather simple step-by-step wizard. When it asks for which program to execute, locate your bat file. The bat-file above assumes you have the php executable in your system path. If not, either add it (Right click My computer, Advanced, Environment variables - path) or do

C:\php\bin\php.exe task1.php

in your bat file. If you're on Linux, you'll need to check up crontabs, which someone else can explain better than me...

freshfish

10+ Year Member



 
Msg#: 10388 posted 11:26 pm on Oct 5, 2005 (gmt 0)

sweet! thanks for the quick response. I didnt think of running it through windows...

However, the script is external on a server...can the batch file still work if it points to [domain.com...]

Thanks again!

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 10388 posted 3:17 pm on Oct 6, 2005 (gmt 0)

maybe remote would work, it all depends on what those scripts are doing.

paulroberts3000

10+ Year Member



 
Msg#: 10388 posted 5:44 pm on Oct 9, 2005 (gmt 0)

you can use wget to run the php through the webserver or set the scripts with the php path at the top if you have php as a cgi on the server.

log in via ssh and type crontab -l to list your crons, 'man crontab' for detailed instructions.

my crontab looks like

0 6 * * * wget -q http://www.example.com/follow_up.php
0 3 * * * wget -q http://www.example.com/reminder.php

[edited by: coopster at 6:28 pm (utc) on Oct. 10, 2005]
[edit reason] removed ulr per TOS [webmasterworld.com] [/edit]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved