Does Cron work in Zend Framework 1.8+?

I am using Zend Framework 1.9.6. I want to start using cron jobs. I'm new to this, so I'm not quite sure how to do this.

I think it would be nice to keep my crowns in /myapp/scriptsor /myapp/application/cronjobs. What do you think? (my application has only the default module)

Once I decided to find a place to store them, how would I start creating a script? Let's say that I want to access the database, check the changes and send an email in the form of a report. I will need to use some components Zend_Dband components Zend_Mail, as well as read the default configuration values. Maybe I might even want to run the Bootprap application? But I don’t need any views, so I don’t know if this was the best idea. I dont know. What should I do and how can I do this? Again, I am using version 1.9.6 and created my application with a command line Zend_Toolscript.

I think there is enough information on the Internet on how to add a cron job to a crontab file. (My web host also offers a tool to do this very simply, so I'm not very interested in this part).

Did you do this in 1.8+ app? Do you have an example script that you could share?

Decision

After publishing this question, I started a new job and became more comfortable working with the Zend Framework. This is what we are doing in the company I'm working on now. I am not saying that this is best practice or ideal, but this information may be useful to someone.

  • Create a top level directory binto save all command line scripts.
  • CLI, , , , .
  • cron bin, . , , . , , . cron , , cron .
+3
2

, , , , cronjob .

, , , , ( , ), , - . , , ( , ), . , , , , ( cron )

( cronjobs ):

function createApplication() {
    require_once 'Zend/Application.php';
    $application = new Zend_Application(
            APPLICATION_ENV,
            CONFIG_PATH . '/application.ini'
    );
    $application->bootstrap();

    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->registerNamespace('Search_');

    return $application;
}

, , $application->run()

, , cronjobs, . $application->bootstrap() , $application->setBootstrap()

 /*
  * @param $path the path to Bootstrap.php, if not set it will default to the 
  *             application bootstrap
  * @return Zend_Application
  */
function createApplication($path = null) {
    require_once 'Zend/Application.php';
    $application = new Zend_Application(
            APPLICATION_ENV,
            CONFIG_PATH . '/application.ini'
    );

    if ( $path ){
        $application->setBootstrap($path);
    }
    $application->bootstrap();

    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->registerNamespace('Search_');

    return $application;
}
+4

cron ZF2. public_html cpanel. , cron, , , , ZF2 -, .

, , , .

, .

. Cron:

Cron
    config
        module.config.php
    src
        Cron
            Controller
                IndexController.php
    autoload_classmap.php
    Module.php 

, , console, :

module.config.php

return array(
    // Placeholder for console routes
    'controllers' => array(
        'invokables' => array(
            'Cron\Controller\IndexController' => 'Cron\Controller\IndexController'
        ),
    ),
    'console' => array(
        'router' => array(
            'routes' => array(
                //CRON RESULTS SCRAPER
                'my-first-route' => array(
                    'type'    => 'simple',       // <- simple route is created by default, we can skip that
                    'options' => array(
                    'route'    => 'hello',
                    'defaults' => array(
                        'controller' => 'Cron\Controller\IndexController',
                        'action'     => 'index'
                        )
                    )
                )

            ),
        ),
    ),


);

IndexController::

<?php
// Cron/src/Cron/Controller/IndexController.php
namespace Cron\Controller;

use Zend\Mvc\Controller\AbstractActionController;

class CronController extends AbstractActionController
{
    public function indexAction()
    {
        echo "hello";
        echo "\r\n";
    }
}

, !

The autoload_classmap.php and Module.php files are standard.

, Zend Manual, , .

trunk ( public_html) ( ) :

path/to/trunk>php public/index.php hello

:

hello
path/to/trunk>

, : http://collabedit.com/58v4v

php , "php", " php". php , ...

.

0

Source: https://habr.com/ru/post/1725748/


All Articles