setup a cron to run php script

hello,
how can I setup a cron to run this php script every hour

http://domain.com/tutorials/?page=check&id=510540
SabrinAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ravenplConnect With a Mentor Commented:
run 'crontab -e', then add following line
0 * * * * /usr/bin/php /path/to/script.php
0
 
sunnycoderCommented:
In /etc/crontab
0 * * * *  /path/to/script
0
 
ravenplCommented:
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
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

 
sunnycoderCommented:
Not even with #! ? ... I am indeed ignorant about PHP
0
 
ravenplCommented:
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
 
ygouthamCommented:
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
 
ygouthamCommented:
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
 
ppfoongCommented:

In my own practise, I run it this way:

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

0
 
sunnycoderCommented:
that was informative .. thanks ravenpl
0
 
ravenplCommented:
-f is optional - but maybe it's more clear what's happening?
0
 
_iskywalker_Commented:
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
 
_iskywalker_Commented:
sry didnt read the comment of ygoutham. he is right
0
 
ravenplCommented:
_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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.