Running a PHP script with Cron

New Web Masters Start Here.

Moderators: Chuck, Vanessa

Running a PHP script with Cron

Postby Rilbur on Tue Aug 31, 2010 10:33 pm

I'm trying to figure out how to run a PHP script using the Cron feature, unfortunately I'm not having much luck. My first effort gave me the following error:

/bin/sh: public_html/processTimes.php: Permission denied

I'm assuming I'm screwing something up somewhere, but I can't seem to find any resources to answer my question. Once I get the cron function running properly, I'll move on to actually writing out the code for processTimes.php; I know I can do that, so the time-consuming aspect of the situation is getting it to run via cron.

Can anyone point me at useful references?
Rilbur
Forum User
 
Posts: 1
Joined: Tue Aug 31, 2010 10:25 pm

Re: Running a PHP script with Cron

Postby Vanessa on Thu Sep 02, 2010 1:18 pm

You either need to make the script 755 for permissions, or specify an interpreter:

Code: Select all
/usr/bin/php /home/yourusername/public_html/processTimes.php
User avatar
Vanessa
Administrator
 
Posts: 649
Joined: Tue Aug 15, 2006 6:31 pm
Location: Virginia Beach, VA

Re: Running a PHP script with Cron

Postby ganesha on Sun Jan 08, 2012 1:45 am

You would need to put "php" before the path to the PHP script, in order to pass the file as an arguement to the PHP cli (Command Line) interpreter:

* * * * * php /home/mywebsite/public_html/cronjob.php

I would not recommend having the cronjob run every minute, though.
ganesha
Forum User
 
Posts: 43
Joined: Thu Dec 29, 2011 7:07 am

Re: Running a PHP script with Cron

Postby elizabethmc on Wed Feb 15, 2012 12:59 am

ganesha wrote:You would need to put "php" before the path to the PHP script, in order to pass the file as an arguement to the PHP cli (Command Line) interpreter:

* * * * * php /home/mywebsite/public_html/cronjob.php

I would not recommend having the cronjob run every minute, though.



Thank you very much for the tips. As someone totally new to cron jobs, I found them very helpful! :)
elizabethmc
Forum User
 
Posts: 2
Joined: Wed Feb 15, 2012 12:56 am


Return to Basic Info - Creating a Web Site

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron