mega888

Cron job setting through Command line for PHP

Administrator July 2, 2013

Cron is driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule. The crontab files are stored here the lists of jobs and other instructions to the cron daemon are kept. Users can have their own individual crontab files and often there is a system wide crontab file (usually in /etc or a subdirectory of /etc) that only system administrators can edit.

For setting cronjob through command line for php in linux server follow the below steps.

* * * * * /usr/bin/php /var/www/html/filename. Php
If you leave the star, or asterisk, it means every.

  • every minute
  • of every hour
  • every day of the month
  • every month
  • every day in the week.

So first star represents minute, second star represents the hour, third star represents the day of month, fourth star represents the month and the fifth star represents the day in week.

For example:
To set cronjob for every 10 minutes. Do the following

0, 10, 20,30,40,50 * * * * /usr/bin/php /var/www/html/filename. Php

While normally the job is executed when the time/date specification fields all match the current time and date, there is one exception: if both “day of month” and “day of week” are restricted (not “*”), then either the “day of month” field (3) or the “day of week” field (5) must match the current day.

Several special predefined values can substitute in the CRON expression

EntryDescriptionEquivalent To

@yearly (or @annually) Run once a year at midnight in the morning of January 1 0 0 1 1 *
@monthly Run once a month at midnight in the morning of the first of the month 0 0 1 * *
@weekly Run once a week at midnight in the morning of Sunday 0 0 * * 0
@daily Run once a day at midnight 0 0 * * *
@hourly Run once an hour at the beginning of the hour 0 * * * *
@reboot Run at startup @reboot

Below figure represents what each asterisk stands for:

*   *   *   *   *  command to execute
┬ ┬ ┬ ┬ ┬ │ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of week (0 – 6) (0 to 6 are Sunday to Saturday, or use names)
│ │ │ └────────── month (1 – 12)
│ │ └─────────────── day of month (1 – 31)
│ └──────────────────── hour (0 – 23)
└───────────────────────── min (0 – 59)

Let’s start working together on your amazing project.

Challenge us. We want to work with you to create the really cool stuff.