Solved

setup a cron to run php script

Posted on 2006-11-06
13
241 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
 
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
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.

930 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

13 Experts available now in Live!

Get 1:1 Help Now