| 08 April 2010
Posted in
Tips and Tricks
One of the new features of Jobs! 1.3 is Job Alerts feature. Jobs! will be able to send new jobs on your web site with a Job Alert weekly or daily basic to your job seekers.
You will be able to send the Job Alerts with 2 ways (On Page Load or With a Cron Job On Hosting Panel)
This document is prepared as a part of Jobs! documentation for On Hosting Panel Part (like cpanel or plesk). I'm going to try to write a blog post about "What The Cron Job is" and "How to Add A Cron Job" (on linux servers)
What is Cron Job?
Cron is a daemon that executes commands at specified intervals. These commands are called "cron jobs." Cron is available on Unix, Linux and Mac servers. Windows servers use a Scheduled Task to execute commands.Cron Job Command Basics
In the following example, the crontab command shown below will activate the cron tasks automatically on the hour:
0 * * * * wget -O - -q -t 1 http://www.instantphp.com/cron.php
the 0 * * * * part in the example above is the time when the cron job is going to happen. There is a diagram below to explain the general crontab syntax
# +---------------- minute (0 - 59)
# | +------------- hour (0 - 23)
# | | +---------- day of month (1 - 31)
# | | | +------- month (1 - 12)
# | | | | +---- day of week (0 - 7) (Sunday=0 or 7)
# | | | | |
* * * * * command to be executed
Thus, the cron command example above means "ping http://www.instantphp.com/cron.php at the zero minute on every hour of every day of every month of every day of the week."
How Jobs! uses cron
Every Jobs! 1.3+ install requires regular actions (If you have activated Job Alerts from your Jobs! configuration) to handle sending Job Alerts to your users
For a small or medium size web sites, you might set up this cron job to run once a day. For a more active site you might want to run that job more often—perhaps every few hours or every hour.How To Add A Cron Job
Cron jobs are scheduled by setting up a "crontab." A crontab is a text file that contains the commands to be run. This file can be created and edited either through the command line interface, or, if you manage your website through a web-based control panel such as cpanel
or Plesk, you will use the web interface. Check with your hosting company for detailed instructions if you are using a web-based control panel.
Add ONE of the following lines:
45 * * * * /usr/bin/lynx -source http://instantphp.com/cron.php
45 * * * * /usr/bin/wget -O - -q -t 1 http://www.instantphp.com/cron.php
45 * * * * curl --silent --compressed http://instantphp.com/cron.php
This would have a lynx
, wget
, or curl
visit your cron page 45 minutes after every hour.
Three options are provided in case either wget, lynx or curl are not installed on the server. Any will do the job well.
See the Cron Job Commands part below to learn more about the crontab file syntax here to set up the cron job to run more or less often.
There are many ways to configure a cron job. If you have full access to crontab features, you should be able to simply paste in one of the above example commands – be sure to replace "instantphp.com" with your own web domain or docroot.
If you're on shared hosting, you should be able to find cron job configuration somewhere in your hosting control panel. Some hosts even have cron "wizards" that walk you through the cron configuration, making it much easier if cron is new to you. On a Windows system you can accomplish the same thing with scheduled tasks to launch Internet Explorer pointed to the URL.
Some hosting companies do not permit local loopback, so using wget, curl or lynx will not work. If this is the case, and they run PHP as a CGI (check with your hosting company to see if this is the case), the following will run the cron locally:-
/usr/bin/php /home/sites/example.com/public_html/cron.php
Cron Job Commands
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>.
Troubleshooting cron jobs
If your hosting company restricts access to cron you have many options.
- Ask the company to give you access, or to set up a cron job for you
- Ask someone else with access to a server to set up a cron job for you. Any Unix, Linux, or Mac server with access to the internet can have a cron job to regularly visit your site. There are also some companies that offer cron services.
- Find an online cron service
. Many are free but with restrictions.
Example Cron Job Commands
You can check the example cron job commands to understand the cron jobs
45 * * * */usr/local/bin/php -q /home/YOUR_USER_NAME/public_html/path/to/cron/file/cron.php (The cron.php script will be called45 minutes after every hour)45 */3 * * */usr/local/bin/php -q /home/YOUR_USER_NAME/public_html/path/to/cron/file/cron.php (The cron.php script will be called45 minutes after every 3 hour)0 * * * */usr/local/bin/php -q /home/YOUR_USER_NAME/public_html/path/to/cron/file/cron.php (The cron.php script will be calledevery hour)
0 */12 * * */usr/local/bin/php -q /home/YOUR_USER_NAME/public_html/path/to/cron/file/cron.php (The cron.php script will be calledevery 12 hour. You can say twice in a day)
Note that the scripts will need to be updated with the path to your directory and URL.
Setting up cron job through the cPanel interface
- Logging into the cPanel interface , scroll to the bottom and look in the "Advanced" section
- Select "Cron Jobs." It is represented with a calendar icon
- Select "Standard"
- Do not use an email address or you will be hit with a notification every time the cron job runs
- Enter the following command: php /home/YOUR_CPANEL_USER_NAME_COMES_HERE/public_html/path/to/cron/file/cron.php
- This is only for your main domain, subdomains are in different folders
- Select the number of times that you would like the cron job to run
- See if it works -you can check whether or not a Cron Job has been run in the Job Alert Logs menu in Jobs! Admin Panel
Security Tip for Cron Job
I also believe that It's a good idea people to remote access to cron.php, in the server, .htaccess or vhost configuration file add this section:<FilesMatch "path/to/your/cron/file/cron.php">
Order Deny,Allow
Deny from all
Allow from localhost
Allow from 127.0.0.1
Allow from THE_IP_OF_YOUR_SERVER
</FilesMatch>THE_IP_ADDRESS_OF_YOUR_SERVER is the IP of your web hosting account. In cPanel this is shown in the left column titled "stats" in the row titled "Shared Ip Address:"
What do you think? Am i missed something?





