Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Cron Jobs Tutorial, So you wanna learn Cron jobs huh ?
OpaQue
post Jan 27 2005, 03:37 AM
Post #1


Administrator
Group Icon

Group: Admin
Posts: 458
Joined: 26-August 04
Member No.: 1



How to setup Basic Cron Jobs.

Ok. Many people are yelling that they cannot configure the crons properly.
Here is a short tutorial which will help you set them. I have tried my best to explain the concept but there can be more advanced configurations.

Basically you will want to run a PHP script file in specific intervals. Suppose you want to execute a php file called maintanence.php every one hour. This is what you do :-

[ smile.gif This tutorial is for noobs, Dont go into detail. Just do as instructed smile.gif ]

The CRON Command is in the Following Format

CODE
[ Minute - Hour - Day - Month - Weekday ] - Command


The COMMAND, can be broken down in
CODE
[PATH OF PHP] [ARGUMENTS] [PATH OF PHP SCRIPT]


So the COMPLETE CRON command can be written as

CODE
[ Minute - Hour - Day - Month - Weekday ]  [PATH OF PHP] [ARGUMENTS] [PATH OF PHP SCRIPT]


The timing is spedified using * symbols
CODE

* * * * * => Execute every minute
0 * * * * => Execute every Hour
0 0 * * * => Execute every mid-night
0 0 0 * * => Execute every Month
0 0 0 0 * => Execute every Weekday


If you did not understand anything till now.. Good, this means you are a noob.. Read ahead tongue.gif

Since this is a UNIX command, You will have to Mention the PATH of PHP. At Astahost,
CODE
PATH TO PHP  : /usr/local/bin/php

( it also same at trap17, if users over there want to use it )

These are the Possible Command line Arguments you can use. This will effect the output. In our case, we will use the -q ( Quiet mode ) argument.
CODE

 -a               Run interactively
 -b <address:port>|<port> Bind Path for external FASTCGI Server mode
 -C               Do not chdir to the script's directory
 -c <path>|<file> Look for php.ini file in this directory
 -n               No php.ini file will be used
 -d foo[=bar]     Define INI entry foo with value 'bar'
 -e               Generate extended information for debugger/profiler
 -f <file>        Parse <file>.  Implies `-q'
 -h               This help
 -i               PHP information
 -l               Syntax check only (lint)
 -m               Show compiled in modules
 -q               Quiet-mode.  Suppress HTTP Header output.
 -s               Display colour syntax highlighted source.
 -v               Version number
 -w               Display source with stripped comments and whitespace.
 -z <file>        Load Zend extension <file>.


The Path of the PHP file Must be Complete absolute path.
If you have an Account at TRAP, And your USERNAME is "tom", Your path will be
"/home/tom/public_html/"

I assume you are familier with the PUBLIC_HTML directory. That is the Root folder where you store your html files.

So lets say that Tom wants to execute my script "maintenance.php" every hour. And it is stored in "public_html/cron/maintenance.php";

So the Complete CRON command would be,

CODE
0 * * * * /usr/local/bin/php -q /home/tom/public_html/cron/maintenance.php


If tom wants to execute it every minute, he would use.

CODE
* * * * * /usr/local/bin/php -q /home/tom/public_html/cron/maintenance.php


There are more Complex forms of Assigning the TIMINGS for these scripts. You can go to CPANEL => Cron Jobs => Standard and set exact time when the script will be executed.


Also, this method used php, you can also use Curl .

-OpaQue
Go to the top of the page
 
+Quote Post
yordan
post Apr 8 2008, 03:22 PM
Post #2


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 1,919
Joined: 16-August 05
Member No.: 7,896



Nice tuto, OpaQue.
I would just add a comment. I use the same syntax, but I add an output file, just in case something fails.
So, my crontabe line would be :
0 * * * * /usr/local/bin/php -q /home/tom/public_html/cron/maintenance.php >/tmp/maintenance.txt 2>&1
With this syntax I redirect the standard output (which is something like "starting", then "finished") as well as the standard error (just in case something goes wrong) to /tmp/maintenance.txt and I am able to have a look in this text file for debugging purposes.
Yordan
Go to the top of the page
 
+Quote Post
iGuest
post Apr 8 2008, 01:15 PM
Post #3


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



Great Help mates.....thanks alo
Cron Jobs Tutorial

Lookin for this longtime, it made my mind so clear now easily set cron jobs, thanks alot mate...



-reply by Arlsn
Go to the top of the page
 
+Quote Post
iGuest
post Jun 27 2008, 12:25 AM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



How to automatic delete all records older than 6 months ?
Cron Jobs Tutorial

I have a database with somw tables and some records .
Into I insert name suername and date (of registration) for a user .

How can I with crone jobs automatically delete ALL the records older thatn 6 Months par example ?

I want it in PHP / Mysql ..Can anyone help me or give some example ?

I'll apreciate it , thanks in advance ;)

-reply by Jeremy

--- admin reply (trap17.com) ---
>> You have to make a PHP program that connects
>> to Database and Deletes those records.
>> Then you run this program in cron with
>> wget / curl / php command :-)

-shree
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How To Remove Bad Sectors Or Bad Clusters From HDD(15)
  2. Enhanced Audio Cd's(2)
  3. How Long To Learn Dreamweaver?(29)
  4. Online Multiplayer Game(11)
  5. Photoshop Tutorial: Forum Signatures(12)
  6. Short "slicing" Tutorial(12)
  7. Excelent Classical Animation Tutorial(5)
  8. A Complete Java Tutorial(4)
  9. Change Fonts On A S60 Phone [tutorial](13)
  10. Yahoo! Messenger Protocol Tutorial - Part 2(2)
  11. Photoshop Tutorial: Carbon Fiber Pattern(6)
  12. Best Way To Learn Javascript(9)
  13. VB.NET: MS-Access Interaction Tutorial (Part I)(17)
  14. [tutorial] Basics Of C Programming - Part 1(11)
  15. [tutorial] Pc-pc Home Networking.(9)
  1. Tutorial: Dreamweaver, 3ds Max, Flash, Html, Css(8)
  2. C# Tutorial : Lesson 3 - Programming Constructs(1)
  3. A Beginner Wanting To Learn How To Make A Web Game(4)
  4. Gimp: Working With Text(5)
  5. Safety(8)
  6. Photographing Fireworks(7)
  7. Website Navigation Hover Buttons Stick So Made Css Today(7)
  8. Linux Beginners - Tutorial On Editors In Linux.(1)
  9. C/c++ -gdb Linux Debug Tool(0)
  10. I Need Help Finding The Best Way To Learn Php(4)
  11. Conditional Statements Of Javascript(1)
  12. Gimp Userbar Tutorial(2)
  13. Choosing Your Computer Before Bying(1)


 



- Lo-Fi Version Time is now: 24th July 2008 - 01:25 PM