Loading...


bookmark - Cron Jobs - Cron Jobs In Cpanel Cron Jobs : Cron Jobs using PHP

Cron Jobs - Cron Jobs In Cpanel - Cron Jobs : Cron Jobs using PHP

 
 Discussion by OpaQue with 38 Replies.
 Last Update: March 27, 2012, 10:06 am ( View Rated (1) ) (View Latest)
Page 1 of 2 pages.
bookmark - Cron Jobs - Cron Jobs In Cpanel Cron Jobs : Cron Jobs using PHP  
Quickly Post to Cron Jobs - Cron Jobs In Cpanel Cron Jobs : Cron Jobs using PHP w/o signup Share Info about Cron Jobs - Cron Jobs In Cpanel Cron Jobs : Cron Jobs using PHP using Facebook, Twitter etc. email your friend about Cron Jobs - Cron Jobs In Cpanel Cron Jobs : Cron Jobs using PHP Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print


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

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

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.


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

-OpaQue

   Thu Jan 27, 2005    Reply         

QUOTE (OpaQue)

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

CODE

0 0 * * * /usr/local/bin/php -q /home/tom/public_html/cron/maintenance.php
cool tutorial, thanks a lot

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

   Thu Jan 27, 2005    Reply         

Errr... what's a cron :P

   Thu Jan 27, 2005    Reply         


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.

   Thu Jan 27, 2005    Reply         

I do not think that my crons are working

   Thu Jan 27, 2005    Reply         

QUOTE (shyam)

Errr... what's a cron  :P


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 :

CODE

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






   Thu Jan 27, 2005    Reply         


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?

   Thu Jan 27, 2005    Reply         

QUOTE (maddog39)

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?


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

   Fri Jan 28, 2005    Reply         

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

   Fri Jan 28, 2005    Reply         

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".

CODE

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.

   Fri Jan 28, 2005    Reply         

Pretty interesting, I've never been with a host that lets me use Cron jobs before, and they sound pretty cool. dunno if I'll ever need to use em, but itz still an interesting how-to. Great job!

   Sun Jan 30, 2005    Reply         

it still doesn't work for me:

my full nightly command (midnight EST):

0 19 * * * /usr/local/bin/php -q /home/gamefaqs/public_html/cron_omgwtflolbbq/daily_purge.php

did i forget something? am i supposed to put a "GET" in somewhere?

please help! this is really important for my site!

thanx in advance

   Sun Feb 6, 2005    Reply         

Finally... but I still don't get it. ;)

7 different people tried it and none of them worked. 7 people.
and none worked.

I'm using the LUE2 source and I need cron jobs to run important parts of it.

I need it for something called karma and something called gems, which is the curreny needed to buy certain items I put in the shop. It's pretty interesting; check it out some time.

Anyway, I also have a game on there to, which also needs crons to give people experciance points and gold to buy stuff from the game's shop.

But yea, if you could help me with it OpaQue, I'd really appreciate it. And I'll let you come to my site anytime you'd like. >_>

   Sat Feb 19, 2005    Reply         

OK im trying these cron jobs out on my cpanel too and I've gotten mixed messages.

I have a php file that just needs to be processed in order for it to work. So all i would do is type in the address of the php file, and it would start processing log files. I want to do this remotely from my webhost site. So I was told once that i could use

CODE


#wget http://www.mysite.com/update.php


and that would run that page at the time I wanted. But it didn't do anything.

Then i saw someone use:

CODE


get http://www.mysite.com/update.php


tried it, nothing happened.

so is there a way to just have the cron job access a remote file by the webaddress?

The way I have it set up is this.

3 Tasks.
Task 1) call on a remote url that is on my home pc to do a log file parse. This is done simply by accessing the php file through any browser, thats it.

Task 2) call on a remote url to do a database backup of the database on that server. Now thats the logs are parsed, it updated the database with all the parsed info.

Task 3) call on a local file to do a database restore to the mirrored database on the webserver, i.e. make the webserver db match my homepc db.


This all works fine if i do it manually. but what command allows the cron job to do it?

   Wed Mar 2, 2005    Reply         

ok I found it.

CODE


/usr/local/bin/GET -C root:pass http://my.ip.add.ress/folder/logs.php?pass=update

this does the trick. loads the remote file.

   Wed Mar 2, 2005    Reply         

QUOTE (DssTrainer)

ok I found it.

CODE


/usr/local/bin/GET -C root:pass http://my.ip.add.ress/folder/logs.php?pass=update

this does the trick. loads the remote file.




ok nevermind that doesnt work.

   Wed Mar 2, 2005    Reply         

I am getting this via e-mail about my cron jobs (directory info protected for security reasons; :angry: ):
/home/mysitename/public_html/directory/protecteddirectory/mail_digests.php: line 1: ?php: No
such file or directory
/home/mysitename/public_html/directory/protecteddirectory/mail_digests.php: line 2:
/aquota.user: Permission denied
/home/mysitename/public_html/directory/protecteddirectory/mail_digests.php: line 3:
mail_digest.php: command not found
/home/mysitename/public_html/directory/protecteddirectory/mail_digests.php: line 4:

: command not found
/home/mysitename/public_html/directory/protecteddirectory/mail_digests.php: line 5: begin:
command not found
/home/mysitename/public_html/directory/protecteddirectory/mail_digests.php: line 6: syntax
error near unexpected token `('
/home/mysitename/public_html/directory/protecteddirectory/mail_digests.php: line 6: `
copyright : © 2000 The phpBB Group'


Any ideas why?

   Fri Mar 11, 2005    Reply         

Wow.. This is very nice tutorial.. very clear, straight and very effective.
i'm noob but follow this tutorial, i can configure cron job successfully :rolleyes:
this can be old topic but i just wanna express my succeed!
thks opaque

   Wed Jun 1, 2005    Reply         

dear shyam Corn is in your cpanel ?
and you can Manage the script with corn to run
for example counter :blink: we can add view to site for count counters :wacko:

Dear Seņor Maniac
corn is working for all trap17 members , but you must active corn first

   Fri Nov 10, 2006    Reply         

Dear All,

How do i set the cronjob if i want to run the task for every 5 minutes in advance mode

coby

   Sun Feb 18, 2007    Reply         

where is the mistake?
Cron Jobs - Cron Jobs In Cpanel

* * * * * /usr/bin/php -q /var/www/virtual/tenzin.Com/htdocs/script.Php
<?php
//("script.Php has chmod 755 script.Php")
$line = 'hello world';
File_put_contents('cron.Txt',$page,FILE_APPEND);
?>


-question by tenzin

   Sat Jan 12, 2008    Reply         

I have this on my cpanel:

/usr/bin/crontab permissions are wrong. Please set to 4755

Is it an error ? and how can I resolve this problem? where to put this dir and so on..

Please help

   Fri Feb 22, 2008    Reply         

hi i am creating my own textbased games using mccodes v2 but i need sum help with the crons i belive it use's curl but i tried typing that in the command box{curl http://www.corrupted.exofire.net/cron_hour...a5cdd16647c77e} it didnt work if i wanted to exicute this http://www.corrupted.exofire.net/cron_hour...ca5cdd16647c77e at a x amount of times what should i type in command box by the way using cpannel please help i am a total noob to crons jobs



Thanks In Advance :lol: :P

   Wed Apr 2, 2008    Reply         

path to php
Cron Jobs - Cron Jobs In Cpanel

Hi. Can someone please tell be how to find the path to php. I'm uusing cpanel

In the past, I found a post that had a command to put in a page, to display the path. Does anybody know. It was really helpfull, just cant find it now. Thanks pat

   Thu Apr 3, 2008    Reply         

Watch out for some hosts running shared servers with cpanel. Some have a limit to how many crons you can have and at what rate they are allowed to go off. I just found out the hard way that my host only allows 5 crons at no less then every 15 min. My cron use was suspended for about 24hrs. The funny thing is it isn't mentioned anywhere, well maybe somewhere amongst the 100 page user agreement, but no where on the site. It just says, to use every minute use *****.

Anywho, what exactly is the '/usr/local/bin/php' used for and is it needed? also, I'm getting errors in my email that state the script cant find my required files. Anyone know why this would be?

Thanx

-reply by ryan

   Sat Apr 19, 2008    Reply         

re: where is the mistake?
Cron Jobs - Cron Jobs In Cpanel

Tenzin, is this a test? the first thing I noticed is .Php and .Txt for an extension... Thats kinda funky. The second is your chmod. 755 is for folders, try 644 for your files.

Also, food for thought, making a call to file_put_contents will create the desired file if it doesn't exist. So, this file should have the correct chmod at creation. You can use this to verify the correct chmod for your files.

Hope that halps

-reply by riin

   Thu May 8, 2008    Reply         

How can we disable a cronjob? I will set a cronjob for every minutes for only one hour. But I don't know how to disable it, so I didn't set.
Can anyone tell me how to disable a cronjob?

Thanks...

   Mon May 26, 2008    Reply         

QUOTE (Erdemir)

Can anyone tell me how to disable a cronjob?
Link: view Post: 391705


  1. Log in to cPanel
  2. Scroll to the bottom of the page, and click Cron jobs in the Advanced section
  3. Click on Standard
  4. Click Delete on the cron job you want to get rid of

   Tue May 27, 2008    Reply         

No such file or directory ?
Cron Jobs - Cron Jobs In Cpanel

I've activated cron job in cpanel, but I get error. What's wrong ?
"/bin/sh: usr/local/bin/php: No such file or directory"
Pls help .. Tq

-reply by han-han

   Tue Aug 12, 2008    Reply         

HTACCES CRON JOB
Cron Jobs - Cron Jobs In Cpanel

Good morning,

I have a host to make cronjob. However, the script called is a bigger level memory is the 32M given to my script is not enough.

I therefore creates a file with the directive htaccess php_value memory_limit 200M, when I call myself this script with a browser my script ends properly because I now has 200M memory.

But now when I set my cron job with this script is well I return errors memory allocation, it seems that the htaccess file is ignored. I tested raise_memory_limit ( "200M"), ini_set ( "memory_limit", "200M"), but nothing done.

The call from my script "php / home / sqdqs / monscript.Php," there is no t'il php parameters to be included in the order (genus php-q)?

Have you any idea of solution?

Thank you

-reply by Smalldevil

   Tue Aug 26, 2008    Reply         

Quickly Post to Cron Jobs - Cron Jobs In Cpanel Cron Jobs : Cron Jobs using PHP w/o signup Share Info about Cron Jobs - Cron Jobs In Cpanel Cron Jobs : Cron Jobs using PHP using Facebook, Twitter etc. email your friend about Cron Jobs - Cron Jobs In Cpanel Cron Jobs : Cron Jobs using PHP Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print


Similar Topics:

Cron Jobs Not Working In Cpanel

Hi, I need to setup a cron job but cPanel says there is an problem with cron: '/usr/bin/crontab permissions are wrong. Please set to 4755 ' Can you please chmod /usr/bin/crontab to 4755 on the alpha server? Thanks in advance. SSH as root an ...more

   20-Jan-2009    Reply         

How To Configure Cron Jobs?

Ok so i have seen the topic about this and in cpanel chose advanced and wrote /usr/local/bin/php -q /home/*myusername*/public_html/cron.php in the field and 40 in the minute slot in front, but with no luck, still the cron job for drupal does not run. Why? ...more

   15-Mar-2009    Reply         

Cron Jobs

Hey guys, hoping someone can help out with this. Basically I just want to set up a cron job on my server (using ComputingHost). Based on what I was reading, we should be adding a script like the following: /home/(AccountName)/public_html/CronScript.php In the a ...more

   02-Oct-2011    Reply         

**** Read Before You Post! **** THIS MAY AFFECT YOUR HOSTING CREDITS   **** Read Before You Post! **** THIS MAY AFFECT YOUR HOSTING CREDITS (52) (8) Cinema 4d | Abstracts   Cinema 4d | Abstracts