Running PHP file automatically using Cron Jobs

What is Cron Job/CronTab?

A cron job is a process that is automatically run in the background of the system at whatever time you set it to run. This can be each day, each hour of every day, upto 1 minute of every hour of every day.

The cron daemon provides the ability for a system administrator to automate the routine running of scripts, tasks or any other server function on a regular basis. It is commonly used to automate system maintenance or administration. For example: to check if the server is down at certain times, to send newsletter at every weekends, to clean invalid data from database everyday etc.

Why do I keep getting an email each time my Cron Job runs?

The email is crontab’s way of notifing you that it has completed (or not) the job you requested it to run.  After successful testing it can be disabled.

If you wish to disable the email (and not output to a log file) then, at the end of each of the cron job command append the below code:

>/dev/null 2>&1

Cron Job can be set from:

  1. Graphical User Interface (Parallels Plesk Panel, X3 Control Panel etc. )
  2. Unix shell (command-line interpreter)

Using Graphical User Interface:

Go to URL: then select Cron Job

The cron job command may vary according to server.

General command that works also on HostGator:

/usr/bin/lynx -source > /dev/null 2>&1


Cron interval selection

Select Common Settings to set time interval and paste the command.

Command that worked with JustHost:

wget –quiet –output-document output_filename /cron_job.php  >/dev/null 2>&1


/usr/bin/wget -O /dev/null -q –delete-after /cron_job.php  >/dev/null 2>&1

Login to your Parallels Plesk Panel – click Domain – select Domain – click Scheduled Task – select User – click New Task

Command that worked with UKFast:

/usr/bin/php /var/www/vhosts/{username}/httpdocs/cron_job.php /dev/null 2>&1

Be Sociable, Share!
You can leave a response, or trackback from your own site.

2 Responses to “Running PHP file automatically using Cron Jobs”

  1. Alessandra says:

    Congratulations! Your blog has been hand selected and
    recognized by add your to receive our – “Blog Star Award” !

    Your blog was chosen by our webmasters, to honor your hard
    work and dedication in providing a quality web log.
    1)Quality Web Content.
    2)Great Design .
    3)Web Log Everyone Will Love To Read .

    Show off our appreciation and display your award on as many pages of your
    site as you wish, by following the directions on the link below:

    To Claim Award Click Here

    Don’t forget to submit your blog to our directory increase your blog

    Click Here To Add Your Blog To AddYourBlog.Com

    Thank You For The Opportunity To View Your Great Blog,

    Keep Up The Good Work,
    Alessandra P.

  2. Neel says:

    Excellent Tutorial for cron jobs. thanks for sharing.
    Neel recently posted..CSS3 HTML5 Button

Leave a Reply

CommentLuv badge

Powered by WordPress