How run zend framework action (inside index controller) by cron every 12 hours?
Asked Answered
S

3

5

How run zend framework action (inside index controller) by cron every 12 hours?

The case:

  1. I have basic(no modules) zend project (1.11) that created by zf tool.

  2. Inside main IndexController exist cronAction() - url http://mydomain/index/cron.

  3. Need to run cronAction() once per 12 hours by cron.

Thanks

Snack answered 29/6, 2011 at 11:19 Comment(0)
C
13

Find the crontab file and add this line:

0 0,12 * * * curl --silent --compressed http://mydomain/index/cron

You can also do it with other tools, such as lynx or wget, not necassarily curl - the above is just an example.

Chain answered 29/6, 2011 at 11:30 Comment(0)
V
5

I know I am bit late but I would like to leave another solution, maybe it help other people, you could run the file in cron if you have your business rule inside model

By creating a file in the public folder with the content below. Ex.: cron.php

 <?php

 // Define path to application directory
 defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

 // Define application environment
 defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));

 // Ensure library/ is on include_path
 set_include_path(implode(PATH_SEPARATOR, array(
        realpath(APPLICATION_PATH . '/../library'),
        get_include_path(),
    )));

 /** Zend_Application */
 require_once 'Zend/Application.php';

 // Create application, bootstrap, and run
 $application = new Zend_Application(
            APPLICATION_ENV,
            APPLICATION_PATH . '/configs/application.ini'
 );
 $application->bootstrap();

 $model = new Application_Model_Name();
 $model->runTask();

Then add a cron tab entry

0 0,12 * * * php /path/to/your/project/cron.php

It should work better than first answer since you will run using PHP CLI then you won't have execution time limit of php script, in case of your script takes more than one minute and you don't need network connection to run that cron job

Victualler answered 24/4, 2012 at 4:18 Comment(0)
P
0

In Zend Framework 2 You can run a cron job using console routes. Take a look at the example posted here: http://collabedit.com/58v4v

Piggott answered 22/5, 2014 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.