-1

Currently, my application have several commands, and every time I have to type the command and run the program manually.

Currently, I am decided to create a crontab to execute those commands. But I am not sure the procedure for creating the crontab based on the Symfony. For example, how to create the crontab, which folder should I put the crontab file in, etc.

Cœur
  • 37,241
  • 25
  • 195
  • 267
J.L
  • 592
  • 5
  • 17
  • 35
  • possible duplicate of [PHP: running scheduled jobs (cron jobs)](http://stackoverflow.com/questions/120228/php-running-scheduled-jobs-cron-jobs) – Giacomo1968 Jun 20 '14 at 05:37

1 Answers1

2

You may find some excellent references from the Ubuntu Docs or from a manual page additionally a nixcraft article can make sense of things, but all a crontab does is execute a shell command,

Each cron defintion gets on line of the file, formatted like so:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

The general form you'll probably want to take is:

0 12,13 * * * cd /var/www/path/to/symphonyappdir/ && php mysymphonything.php

the cd should generally use an absolute path to your app dir, the && is logic for 'and', so if the 'cd' fails (presumably because the directory wasn't accessible) the second half wont execute.

Save this file anywhere, the crontab manual suggest that users should not directly edit crontab files.

Open your primary crontab file with:

crontab -e

Or add a new file to a crontab with:

crontab mynewcronfile

You can also get a current crontab file contense with:

crontab -l
Community
  • 1
  • 1
ThorSummoner
  • 16,657
  • 15
  • 135
  • 147