Cron Jobs

Status
Not open for further replies.

vrepublik

New Member
Messages
1
Reaction score
0
Points
0
Hi, I'd like to run a PHP cron script: http://www.virtualrepublik.net/pages/cron.php, every day at 00:00 GMT but I have been having some problems with the commands to run the file.

Would you be able to give me a command example or set it up for me?

Regards
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
cPanel has a cron job manager. I would recommend running it at 23:59 or something slightly before then, because usually on a shared hosting company everyone runs their cron job at 00:00, so it can lag a bit. Not sure what it like on x10hosting, though.
 

cybrax

Community Advocate
Community Support
Messages
764
Reaction score
27
Points
0
Regular Cron problems

1. the command string is wrong, there must be space between php and /home (/php /home/ = good , /php/home/ = wrong)

/usr/bin/php /home/your_username/public_html/some_folder/cron_job_script.php

2. the cron account has limited permissions, so not all functions are avaialable to a script such as mail()

3. you cannot run cron jobs every minute on the free accounts, I believe the lower limit is 15 minute intervals

Running cron jobs at minutes past the hour is also good practice as callummacrae suggested to avoid slowing the server up.
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
It doesn't really slow the server up - as a cron job runs, it is added to a big list of cron jobs which are then ran in order (as opposed to being ran all at the same time, which could take out the server). As 00:00 is so popular, your cron job could be added quite far down a huge list and so there will be a delay. I don't know how they're ordered (or collected, w/e), but my first guess would be by username - in which case "vrepublik" isn't a great username to have ;-)

Again though, I'm not sure, and I don't even know whether it applies on x10hosting.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Code:
/usr/bin/php -q  /home/igor/public_html/pages/cron.php >>/home/igor/public_html/pages/cron_log.txt 2>&1

1. Replace 'igor' with your cPanel username

2. This logs any errors or output to cron_log.txt which helps with debugging, etc. By adding an echo command outputting the time/date will keep a record of the file running.

3. Depends on where you got the cron file, if you did not write it yourself. Some scripts require a special variable to be added to the URL when run from the web and these cron jobs need to be run using wget.
 
Status
Not open for further replies.
Top