PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Sep 22, 2019 5:53 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: cron job
PostPosted: Mon Feb 25, 2008 12:07 pm 
Offline
Forum Commoner

Joined: Wed Jan 23, 2008 12:31 pm
Posts: 56
I created a php script and I want it to run everyday at 10:30am. How would I make that into a cron job ?


Top
 Profile  
 
 Post subject: Re: cron job
PostPosted: Mon Feb 25, 2008 12:30 pm 
Offline
Tranquility In Moderation
User avatar

Joined: Sun Feb 06, 2005 8:18 pm
Posts: 5001
Location: Indiana

_________________
- A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.


Top
 Profile  
 
 Post subject: Re: cron job
PostPosted: Mon Feb 25, 2008 12:34 pm 
Offline
Forum Commoner

Joined: Wed Jan 23, 2008 12:31 pm
Posts: 56
Is it possible to run the cron job on the command line to test ?

So far I've added the line:

30 10 * * * /script

Instead of having this line referencing to php:

/usr/bin/php /home/me/public_html/myscript.php

will adding this line at the top be the same:

#!/usr/local/bin/php -q


Top
 Profile  
 
 Post subject: Re: cron job
PostPosted: Mon Jun 28, 2010 1:20 pm 
Offline
Forum Commoner

Joined: Wed Mar 12, 2003 5:35 pm
Posts: 65
I'm having a similar problem, but here is my environment and issue.

I'm using Putty for my connection to SSH. After logging in I use the command

crontab -e which opens the editor

I put the following commands in

# email for course start alert everyday at 8 am
00 08 * * * /usr/local/bin/php /var/www/vhosts/wtionline.cc/crontasks/emailcoursealert.php

My php file is listed under my hosting directory as stated in the path.

First, my question is how do I SAVE this file and where is it placed on the hosting server?
If I want to edit it again how do I do this. I'm assuming these are all command line functions, but not familiar with linux or putty.


Top
 Profile  
 
 Post subject: Re: cron job
PostPosted: Mon Jun 28, 2010 1:29 pm 
Offline
DevNet Master
User avatar

Joined: Mon Feb 24, 2003 11:12 am
Posts: 2572
Location: The Republic of Texas

_________________
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.


Top
 Profile  
 
 Post subject: Re: cron job
PostPosted: Mon Jun 28, 2010 2:49 pm 
Offline
Forum Commoner

Joined: Wed Mar 12, 2003 5:35 pm
Posts: 65
When I login it says "The program included with the Debian GNU/Linux system are free software. So I tried your Ctrl o and nothing happened. Also tried the SHIFT : but just got the characters :. The Ctrl just backed up the cursor one character to the left.

I will continue to google putty and see if I find other information.

Any other suggestions welcomed.


Top
 Profile  
 
 Post subject: Re: cron job
PostPosted: Mon Jun 28, 2010 2:55 pm 
Offline
DevNet Master
User avatar

Joined: Mon Feb 24, 2003 11:12 am
Posts: 2572
Location: The Republic of Texas

_________________
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.


Top
 Profile  
 
 Post subject: Re: cron job
PostPosted: Mon Jun 28, 2010 3:28 pm 
Offline
Forum Commoner

Joined: Wed Mar 12, 2003 5:35 pm
Posts: 65
Yes I found figured out it was using the vi editor from my hosting company. I was able to create a file with my command and now just waiting to see if it works. I'm assuming the job is ready to run based on the Linux Server and it looks for cron jobs automatically.


Top
 Profile  
 
 Post subject: Re: cron job
PostPosted: Tue Jun 29, 2010 10:23 am 
Offline
Forum Commoner

Joined: Wed Mar 12, 2003 5:35 pm
Posts: 65
My job is not executing for some reason.

I contacted my hosting company to figure out the path for the file location and used pwd to get that information. Here is my final script

0 10 * * * /homepages/41/d283671596/crontasks/emailcoursealert.php


Is there a way for me to get a notice of whether the job had errors or executed at all. This should have ran at 10 AM Central time, which is the time of my server. The php script should be sending me an email message.

This is the only line in my script file.


Top
 Profile  
 
 Post subject: Re: cron job
PostPosted: Tue Jun 29, 2010 1:27 pm 
Offline
DevNet Master
User avatar

Joined: Mon Feb 24, 2003 11:12 am
Posts: 2572
Location: The Republic of Texas
Well, if you are using the !#/usr/bin/php method then you need to set emailcoursealert.php to be an executable.
Syntax: [ Download ] [ Hide ]
CHMOD +x emailcoursealert.php


For the mail issue, add this to the top of the crontab:
Syntax: [ Download ] [ Hide ]
MAILTO=you@example.com

_________________
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group