Cron job setting through Command line for PHP
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.
- /user/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, /user/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
- Cron Entry: @yearly / @annually
- Description: Run once a year at midnight on January 1
- Equivalent: 0 0 1 1 *
- Cron Entry: @monthly
- Description: Run once a month at midnight on the first day of the month
- Equivalent: 0 0 1 * *
- Cron Entry: @weekly
- Description: Run once a week at midnight on Sunday
- Equivalent: 0 0 * * 0
- Cron Entry: @daily
- Description: Run once a day at midnight
- Equivalent: 0 0 * * *
- Cron Entry: @hourly
- Description: Run once an hour at the beginning of the hour
- Equivalent: 0 * * * *
- Cron Entry: @reboot
- Description: Run once at system startup
- Equivalent: @reboot
Below figure represents what each asterisk stands for: command to execute
- Minute : 0–59
- Hour : 0–23
- Day of Month : 1–31
- Month : 1–12
- Day of Week : 0–6 (Sunday to Saturday or names)
Published on July 2, 2013



