Cron Job with Zend Framework

php -q -f /path/cronscript.php

/**************** I. ver. without Models**************/

    $application = new Zend_Application(
                    APPLICATION_ENV,
                    APPLICATION_PATH . '/configs/application.ini'
    );

 $application->getBootstrap()->bootstrap(array('db'));
$db = $application->getBootstrap()->getResource('db');
$rows = $db->fetchAll("SELECT .....");
 //DELETE
        try {
            $condition = array(
                'id  IN(?)'=> $rows
            );
            $delete = $db->delete('users',$condition);
            Zend_Debug::dump($delete);
        } catch (Zend_Exception $e) {
            echo $e->getMessage();

        }

        /**************** II. ver.  using models **************/       

            $application = new Zend_Application(
                    APPLICATION_ENV,
                    APPLICATION_PATH . '/configs/application.ini'
    );

   $application->bootstrap();

 //in controller
$db = Zend_Db_Table::getDefaultAdapter();   
$rows = $db->fetchAll("SELECT .....");

//Model
  $model = new Model_DbTable_Users();
  if (!empty($rows)) {
      $result = $model->deleteUsersById($rows);
      Zend_Debug::dump($result);
  }

In II. version I use $application->bootstrap(); instead of  $application->bootstrap()   ->run();

run(): If so, it registers the bootstrap with the ‘bootstrap’ parameter of the front controller, and dispatches the front controller.

http://www.masnun.me/2011/08/21/using-zend-framework-models-and-libraries-from-command-line-or-cron-job.html

http://www.mediabandit.co.uk/blog/248_setting-up-cron-with-zend-framework-1-11

Blogbook : PHP | Javascript | Laravel | Corcel | CodeIgniter | VueJs | ReactJs | WordPress