1
How do I use cronjobs in Cakephp, need to call a controller action on the linux server, is the script path?
I’ve tried it here and it didn’t work!
1
How do I use cronjobs in Cakephp, need to call a controller action on the linux server, is the script path?
I’ve tried it here and it didn’t work!
3
Ideally you do this in your layer of Model
, I think you should rethink this option of calling directly from Controller
.
For this, you must first create a task shell, which will be executed on your server’s task scheduler. Let’s assume that you want to clear a table photos every half-hour, then you create a task from a file app/Console/Command/PhotoShell.php
sort of like this:
class PhotoShell extends AppShell {
public function limpar() {
ClassRegistry::init('Photo')->limpar();
}
}
And your model Photo
would have the method limpar()
thus implemented:
public function limpar() {
$this->query('TRUNCATE ' . $this->useTable);
}
Ready, done this, just include in your cronjobs:
0,30 * * * * /app/Console/cake Photo limpar
Remembering that the file cake must have the appropriate execution permissions.
2
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)
http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html
I had already seen this link but had not understood, as @Paulorodrigues explained, it was easy.
Browser other questions tagged cakephp cron
You are not signed in. Login or sign up in order to post.
Paulo, I will follow your tips and make the changes, thanks!!! ;)
– Williams