PHP programmer of bangladesh
A PHP Programmer of Bangladesh

How to setup Basic Cron Jobs?

August 1st 2007 in Help, LINUX


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 :-

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

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

CODE

0 0 0 * * /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.

Reference: http://www.trap17.com/index.php/cron-jobs-cron-jobs-cpanel_t6321.html


Trackbacks

close Reblog this comment
blog comments powered by Disqus

How to setup Cron Job Using Cpanel?

Let’s get started. Log in to your cPanel and look for the Cron Jobs icon:

Click on the image and you’ll be asked to choose your experience level. If you’re reading this, you want to click on Standard.
Creating a Cron Job
Now that you’re at the Standard Cron Manager, let’s create a cron job. You can set [...]

How to setup Cron Job Using Cpanel?Previous Entry

HELP NEEDED FOR BANGLADESHI FLOOD AFFECTED PEOPLE

Hello EVERYBODY

Bangladeshi People are fall in a natural Disaster and hereby they need help from all. I am collecting Helping funds.

So, I would like to request you all to contact me if you wish to help those people who really need us. I think every sensible person should step forward to help those people. Allah [...]

HELP NEEDED FOR BANGLADESHI FLOOD AFFECTED PEOPLENext Entry

Where i am ???



Currently I am working in Right Brain Solution(RBS) as a Software Engineer(Team Leader). I start my journey in RBS from 6th Nov, 2007.
Where i Was???
I am a php professional from Bangladesh. I start my journey as a professional from 1st july, 2006 in EVOKNOW Incorporation. I was there for one and half year. My Position was there "Software Engineer(Lead Developer)". I left EVOKNOW at 5th Nov, 2007.
Self Formed
I do some freelancing work with some of my friends under this name. Our dream is to make it world famous in the field of web development & solution. If you would like to work with us, send us your proposal to technopeoplebd@gmail.com
Social Networks
View Md. Mahabubul Hasan Masud's profile on LinkedIn
Moonrise: What i feeling???
Feelings from moonrise
More items See these feelings on moonrise