Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Cron Jobs - Cron Jobs In Cpanel


38 replies to this topic

#1 OpaQue

    Administrator

  • Admin - The Official Guru
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1,895 posts
  • Gender:Male
  • Location:Somewhere in Time & Space.
  • Interests:Discovering Myself.
  • myCENT:-129.97

Posted 27 January 2005 - 04:06 AM

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

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

The CRON Command is in the Following Format

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

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

So the COMPLETE CRON command can be written as

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

The timing is spedified using * symbols
* * * * * => 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 :P

Since this is a UNIX command, You will have to Mention the PATH of PHP. At Astahost,
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.
  -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,

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

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

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

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

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.


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

-OpaQue

#2 alapidus

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 74 posts
  • Location:Connecticut
  • Interests:sports, video games, computers, tv...

Posted 27 January 2005 - 05:24 PM

OpaQue, on Jan 26 2005, 11:06 PM, said:

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

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

View Post

cool tutorial, thanks a lot

but shouldn't you use * * * * * for the time if you wanted it to run every minute?

#3 shyam

    Newbie [Level 3]

  • Kontributors
  • PipPipPip
  • 48 posts

Posted 27 January 2005 - 07:30 PM

Errr... what's a cron :P

#4 itsme

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 14 posts

Posted 27 January 2005 - 09:47 PM

I have been looking for this information for some time now. Thanx!
All other Cron help was for experts. I could not figure the correct command and can now see what is ment by argument. Will be trying this info on my site. You see I need it to update information every 2 weeks.

#5 Seņor Maniac

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 272 posts
  • Location:(&gt;0_0)&gt;oooO Hadoken
  • Interests:I like almost everythin.

Posted 27 January 2005 - 10:20 PM

I do not think that my crons are working

#6 Zaideu

    Member [Level 2]

  • Kontributors
  • PipPipPipPipPip
  • 88 posts

Posted 27 January 2005 - 10:23 PM

shyam, on Jan 27 2005, 08:30 PM, said:

Errr... what's a cron  :P

View Post

It does an action every "X B)
When you have a file : update.php
And you want to load it every day at midnight. You don't have to go on this page yourself. The cron does it and you don't have to do anything, it is really usefull B) You can insert some SQL requests on your file update.php, and it will be done everyday.
Exemple :
update.php

mysql_query("UPDATE members SET point = point + '1'");
If the cron is activated on the page update.php, everyday your members will get 1 more point :D

#7 maddog39

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 208 posts
  • Location:LI, New York
  • Interests:Web programming, computer programming, computer games, and Play Station2. :D

Posted 27 January 2005 - 11:00 PM

Ok, so I still dont get the point of cron jobs. Are they just server settings that allow you to execute a command within a set ammount of time?

#8 Zaideu

    Member [Level 2]

  • Kontributors
  • PipPipPipPipPip
  • 88 posts

Posted 28 January 2005 - 09:52 AM

maddog39, on Jan 28 2005, 12:00 AM, said:

Ok, so I still dont get the point of cron jobs. Are they just server settings that allow you to execute a command within a set ammount of time?

View Post

Exactly ! :D It can be useful but it isn't essential. If you don't need it, don't use it :P

#9 maddog39

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 208 posts
  • Location:LI, New York
  • Interests:Web programming, computer programming, computer games, and Play Station2. :D

Posted 28 January 2005 - 05:14 PM

OK. Ya I dont think id have any use for it but just wondering. :P

#10 Roly

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 144 posts
  • Location:Arizona
  • Interests:school dunno whatever

Posted 28 January 2005 - 11:09 PM

I have a question, what if we don't have a cpanel, where do we set up the cron job?
This program has led me into making my own PHP cron >_>
I have a MySQL table named "other" with fields "name'" and "content".
if(mysql_result(mysql_query('content','other','name = \'cron\' AND content <= UNIX_TIMESTAMP()-60*60*24'), 0))
{
  // cron stuff goes here
 

  // Update the cron time
  mysql_query('UPDATE other SET content = UNIX_TIMESTAMP WHERE name = \'cron\'');
}

This is sort of the way my script is, it's a good script 'cause it doesn't take much time out of the user. It's in the head file so it'll get run when needed. The cron stuff gets runned every day.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users