Solved

setup a cron to run php script

Posted on 2006-11-06
13
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

749 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