How to run cron job with zend framework 2(如何使用 Zend 框架 2 运行 cron 作业)
问题描述
我在 Zend Framework 2 中构建了应用程序.我想设置 cron 作业来更新我的产品.我知道这样的脚本应该从公共文件夹之外运行,但不幸的是我在 cron 中的脚本需要使用框架文件.
我该怎么做?
我想出的唯一方法是从公共文件夹外部运行脚本,然后添加一些哈希或密码并重定向到
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?
推荐答案
我强烈建议使用 CLI 来满足此类需求.
I strongly recommend to use CLI for such requirement.
- 在应用程序模块中创建一个带有 updateAction() 的 ConsoleController.
将控制台路由添加到您的应用程序模块的
module.config.php
:
- Create a ConsoleController with an updateAction() inside the application module.
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'
)
)
)
)
)
)
);
现在打开终端
Now open the terminal and
$ cd /path/to/your/project
$ php public/index.php updateproducts
仅此而已.希望有帮助.
Thats all. Hope it helps.
这篇关于如何使用 Zend 框架 2 运行 cron 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Zend 框架 2 运行 cron 作业


- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01