Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have application built in Zend Framework 2. I would like to set cron job for updating my products. I know scripts such as this should be run from outside of public folder, but unfortunately my script in cron needs to use framework files.
How can I do this?
The only way I figured out is to run script from outside of public folder then add some hash or password and redirect to

www.domain.com/cron/test

So I will have all framework functionality.
Will it be secure? Maybe there is a other way?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
378 views
Welcome To Ask or Share your Answers For Others

1 Answer

I strongly recommend to use CLI for such requirement.

  1. Create a ConsoleController with an updateAction() inside the application module.
  2. Add a console route to your application module's module.config.php:

    array(
        'router' => array(
            'routes' => array(
            ...
            )
        ),
    
    'console' => array(
        'router' => array(
            'routes' => array(
                'cronroute' => array(
                    'options' => array(
                        'route'    => 'updateproducts',
                        'defaults' => array(
                            'controller' => 'ApplicationControllerConsole',
                            'action' => 'update'
                        )
                    )
                )
            )
        )
    )
    );
    
  3. Now open the terminal and

    $ cd /path/to/your/project
    $ php public/index.php updateproducts
    

Thats all. Hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...