How to run a zend framework action (inside an index controller) cron every 12 hours?

How to run cend zend (internal index controller) action every 12 hours?

Happening:

  • I have a basic (without modules) zend project (1.11) created by the zf tool.

  • Inside the main IndexController there is cronAction () - url http: // mydomain / index / cron .

  • It is required to run cronAction () once every 12 hours cron.

thank

+5
source share
3 answers

Locate the crontab file and add this line:

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

You can also do this with other tools like lynx or wget, rather than freezes - this is an example.

+13
source

, , , , , cron, -

. : 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();

cron

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

, , PHP CLI, php script, , script , cron

+5

Zend Framework 2 cron . : http://collabedit.com/58v4v

0

All Articles