Monday, July 25, 2016

Set up cron jobs or crontab in Cakephp




Before stating to set up Cron jobs in your server you have understand and know what the Cron jobs is?

Cron is a Linux utility which schedules a command or script on your server to run automatically at a specified time and date. A cron job is the scheduled task itself. Cron jobs can be very useful to automate repetitive tasks.

Cron syntax
  */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)
To understand more please follow this link console-and-shells

1 - Create model News.php
App::uses('AppModel', 'Model');
class News extends AppModel
{
    public function sendNews()
    {
 $this->updateAll(array('is_disabled' => 1), array('delivery_time' => date('H:i').':00'));
    }
}

2- Create NewsSell in Cosole.

class NewsSell extends AppShell
{
   public function main()
   {
    App::import('Model', 'News');
    $News  = new News();
    $News->sendNews();
   }
}

3- Write command in crontab

-> type "crontab -e" in your terminal
->  set cron path "*/1 * * * * /var/www/vhosts/yourwebroot/html/app/Console/cake News"
-> save

Finally, I hope that this article will help you to get reach at the point.

Problem with cron jobs cakephp.





0 comments:

Post a Comment