How do I use cronjobs in CakePHP, I need to call an action from a controller on linux server, is it the script path?
I've tried it here and it did not work!
How do I use cronjobs in CakePHP, I need to call an action from a controller on linux server, is it the script path?
I've tried it here and it did not work!
Ideally you should do this on your Model
layer, I think you should rethink this option by directly calling Controller
.
To do this, you must first create a task shell , which will run in the task scheduler of your server. Let's suppose you want to clean a photos table every half hour, so you create a task from a app/Console/Command/PhotoShell.php
file something like this:
class PhotoShell extends AppShell {
public function limpar() {
ClassRegistry::init('Photo')->limpar();
}
}
And your model Photo
would have the limpar()
method implemented like this:
public function limpar() {
$this->query('TRUNCATE ' . $this->useTable);
}
Ready, done, just include in your cronjobs :
0,30 * * * * /app/Console/cake Photo limpar
Remembering that the cake file must have the proper execute permissions.
From the cakebook itself
*/5 * * * * cd /full/path/to/app && Console/cake myshell myparam
# * * * * * 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)