Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

setup a cron to run php script

Posted on 2006-11-06
13
Medium Priority
?
252 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Fine Tune your automatic Updates for Ubuntu / Debian
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to moveā€¦
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.
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

926 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