Difference between revisions of "Cron Jobs"

From Hostek.com Wiki
Jump to: navigation, search
(cPanel/Linux - Setting up Cron Jobs)
Line 4: Line 4:
 
*[http://hostek.com/tutorials/cpanel-x3-cronjob.html How to setup a cron job]
 
*[http://hostek.com/tutorials/cpanel-x3-cronjob.html How to setup a cron job]
  
#Please keep in mind that you may have to have a cron job be executed by a specific service.<br />
+
*Please keep in mind that you may require a specific service for a cron job to get properly executed. For example, a PHP requires /usr/bin/php to run-- like the cron below:<br />
#For Example a PHP File to be run:
+
 
  /usr/bin/php -q /home/user/public_html/cron.php
 
  /usr/bin/php -q /home/user/public_html/cron.php
  
#If you do not want the email to be received for confirmation you will need to add the following to the end of your request:
+
*If you do not want email confirmation for each successful cron, you will need to add the following to the end of your cron job:
  
 
  /usr/bin/php -q /home/user/public_html/cron.php > /dev/null
 
  /usr/bin/php -q /home/user/public_html/cron.php > /dev/null
  
#If you are using get for a http request it would be like this:
+
*If you want to use a HTTP URL in your cron, it would look like the following. Note that if your URL has special characters such as '&' or ':', you can include those normally.
  /usr/bin/curl --silent --output /dev/null <nowiki>http://yourdomain.com/cron.php</nowiki>
+
 
 +
  /usr/bin/curl --silent --output /dev/null <nowiki>http://yourdomain.com/cron.php:request&action=activate</nowiki>
  
 
==WCP/Windows - Setting up Cron Jobs==
 
==WCP/Windows - Setting up Cron Jobs==

Revision as of 18:28, 13 July 2017


cPanel/Linux - Setting up Cron Jobs

  • Please keep in mind that you may require a specific service for a cron job to get properly executed. For example, a PHP requires /usr/bin/php to run-- like the cron below:
/usr/bin/php -q /home/user/public_html/cron.php
  • If you do not want email confirmation for each successful cron, you will need to add the following to the end of your cron job:
/usr/bin/php -q /home/user/public_html/cron.php > /dev/null
  • If you want to use a HTTP URL in your cron, it would look like the following. Note that if your URL has special characters such as '&' or ':', you can include those normally.
/usr/bin/curl --silent --output /dev/null http://yourdomain.com/cron.php:request&action=activate

WCP/Windows - Setting up Cron Jobs

  1. With a recent update to Windows Control Panel (WCP) we've added Windows cron jobs. To make use of these, login to WCP and find the Cron Jobs tool (clock icon). It'll be on the bottom of the panel. To set up a cron on Windows:
    1. Click Add
    2. Choose a name for the Cron
    3. Place a URL to be executed
    4. If this is a simple cron, keep the Easy mode selected. Advanced gives you complete control over when your cron runs.
    5. Choose the interval at which the cron runs
    6. Click Save

Common Cron Failures

  • Not Firing: When You Specified Make sure your time format is correct. Sometimes extra zeroes or an extra asterisk (*) makes their way into the mix. This will cause the cron to fire at the wrong time, or a complete failure.
  • Long Wait Times: If your script has long processes it handles and you've manually changed the timeout time in the configurations, this may not be passed to the cron. See if you can shorten the processing time. If you need to try and lengthen the timeout time on the cron, send an email to support@hostek.com with the details of your cron job.
  • Multiple Firings: Most time when you see multiple firings it's actually that the cron is executing an initial part of the script, failing somewhere after that, and trying again. Try setting up a flag, most usually a simple email, at the very end of the code to determine if this is what's causing the double firings.
  • No Firings: If your cron is not failing at all, you may need to look at the logs as to why. To do this, send an email to support@hostek.com. However, the most common reasons for why a cron wouldn't fire at all are below.
    • Missing/invalid script path: If you need the script at D:\home\domain.com\wwwroot\myscript.php to fire, but you say it's at D:\home\domain.com\myscript.php then nothing will fire.
    • Bad URL: Most crons need to have HTTP:// in front of the URL path. Make sure to check the URL you're using.