Web Hosting Forum

Go Back   Web Hosting Forum > CPanel Help
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old 09-05-2007, 09:06 AM   #1 (permalink)
Donk
Junior Member
 
Join Date: Sep 2007
Posts: 11
Default Cron Jobs

I wish to run a cron job on one of my accounts but reading through other forums there appear to be many ways to enter the URL. The most common being:

either
/usr/bin/php /usr/home/myusername/public_html/cron.php
or
wget -q -O /dev/null http://mydomain.com/cron.php

What is the difference? Is either better, or makes more efficient use of resources and will both or either work on dream-hosting?
Donk is offline   Reply With Quote
Old 09-05-2007, 02:35 PM   #2 (permalink)
Elliot
Administrator
 
Join Date: Aug 2007
Posts: 1
Default

Hi,

wget will actualy run the php script via the web server (i.e. apache). This means its exactly the same as you going to the url manually to run the php script.

The preferred method (as its run from the command line so bypasses apache) is using php.

The best way is:

php -f /home/username/public_html/cron.php

Bare in mind also that because its a cron run via the command line, it doesn't even need to be in the public_html directory, for added security you could keep it one dir above so its not accessable from the web root.

To make sure your script works ok via the command line, you can log into your shell and run php -f /path/to/file.php to test it and see the output.

Let me know if you have any questions.

Elliot.
Elliot is offline   Reply With Quote
Old 09-05-2007, 09:42 PM   #3 (permalink)
Donk
Junior Member
 
Join Date: Sep 2007
Posts: 11
Default

Thanks for your reply just a few more questions

1/ What does the f flag do?

2/ Can I get the script to create a log or must I do that in php.

3/ What's the best time of day (or night) to schedule it.

Regards

Bob
Donk is offline   Reply With Quote
Old 09-10-2007, 10:12 AM   #4 (permalink)
admin
Administrator
 
Join Date: Aug 2007
Posts: 50
Default

Hi,

1) The -f just means Parse and execute the file specified, technically its not needed.

2) If on the actual cron command you do:
php somefile.php > operation.log 2>> errors.log

That will put all the output from the script into operation.log and any script errors into errors.log, you can also get it to email you the outputs (which can be setup in cpanel)

3) It depends what the cron does, if it is quite intensive then its always best to run it when your site is at its quietest.

Admin
admin is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:59 AM.


© Dream Hosting 2007

LinkBacks Enabled by vBSEO 3.0.0