Solved

setup a cron to run php script

Posted on 2006-11-06
13
242 Views
Last Modified: 2010-04-20
hello,
how can I setup a cron to run this php script every hour

http://domain.com/tutorials/?page=check&id=510540
0
Comment
Question by:Sabrin
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17879728
In /etc/crontab
0 * * * *  /path/to/script
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 500 total points
ID: 17879786
run 'crontab -e', then add following line
0 * * * * /usr/bin/php /path/to/script.php
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17879794
Ups - sunnycoder was faster - but in fact little too short.
php scripts usually are written in such way, that they can't be run from command line like: ./script.php
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 45

Expert Comment

by:sunnycoder
ID: 17879801
Not even with #! ? ... I am indeed ignorant about PHP
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17879812
Yeap - php wos not really designed to be used in commandline scripts. Therefore php will dosplay the
#!/usr/bin/php
as it's first output - LOL !
It can be avoided/workarounded - but common users simply start the script from "<?php"
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 17879813
all you need to do is

php /path/to/my/script.php

this line needs to go into crontab.

ravenpl has just hit it on the head.  just ensure that you run it that way or you can do the alternate way

you can do

wget http://youhost.ip.com/path/to/script.php

that can also be added to the script.  Only hitch being that the downloaded files are saved in /root/ directory which might require a clean up.

g
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 17879816
the wget command can be put into the crontab and you can pass on any value depending on the script.  you can include the command straight into the crontab file or can put that into a shell script and add the same to the crontab.
0
 
LVL 14

Expert Comment

by:ppfoong
ID: 17879828

In my own practise, I run it this way:

0 * * * * /usr/bin/php -f /path/to/script.php

0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17879835
that was informative .. thanks ravenpl
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17879844
-f is optional - but maybe it's more clear what's happening?
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 17879849
make it easy, out in cron a wget:
0 * * * * wget http://domain.com/tutorials/?page=check&id=510540
so you are sure, that apache (or your webserver) will do the job, in some context that is better.
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 17879850
sry didnt read the comment of ygoutham. he is right
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17879855
_iskywalker_: don't parrot ygoutham's responces. Especially suggesting wrong code. In Your example You need
0 * * * * wget "http://domain.com/tutorials/?page=check&id=510540"
Figure out by Yourself - why.

BTW: wget is good sollution, IF the script is put on some website. otherwise no bonus :(
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now