drl47263 2014-01-10 23:05
浏览 26
已采纳

命令行中的ZF脚本为cron

I am trying to figure out how to make a Zend Framework script to run as a cronjob from a command line, but the bootstrap setup below seems to fail:

define('BASE_PATH', realpath(dirname(__FILE__) . '/../') . '/');
define('APPLICATION_PATH', BASE_PATH . 'application/');
define('APPLICATION_ENV', 'live');

// Ensure library/ is on include_path
set_include_path(
        implode(PATH_SEPARATOR, array(
            realpath(BASE_PATH . 'library'),
            realpath('/usr/src/ZendFramework-1.12.3/library')
            ) // closes array
        ) // closes implode
        . get_include_path()
    );

require_once 'Zend/Application.php';

$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
// Load only the ressources that you need
$application->getBootstrap()->bootstrap(array('db', 'mail'));

It fails on the $application->getBootstrap()->bootstrap(array('db', 'mail')) line. I am puzzled. It seems to be able to access frontController module, but neither db or mail modules works. Any ideas what it could be?

Edit: Below are the error details:

Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'Resource matching "db" not found' in /usr/src/ZendFramework-1.12.3/library/Zend/Application/Bootstrap/BootstrapAbstract.php:694
Stack trace:
#0 /usr/src/ZendFramework-1.12.3/library/Zend/Application/Bootstrap/BootstrapAbstract.php(632): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('db')
#1 /usr/src/ZendFramework-1.12.3/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(Array)
#2 /www/.../live/htdocs/v2/cron/bootstrap.php(26): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap(Array)
#3 /www/.../live/htdocs/v2/cron/send-leads.php(2): require_once('/www/...')
#4 {main}
  thrown in /usr/src/ZendFramework-1.12.3/library/Zend/Application/Bootstrap/BootstrapAbstract.php on line 694
  • 写回答

2条回答 默认 最新

  • douzheng9221 2014-01-13 14:58
    关注

    Changing

    $application->getBootstrap()->bootstrap(array('db'))

    to

    $application->getBootstrap()->bootstrap(array('multidb'))

    fixes the issue. I am not exactly sure about the mail resource, though, but judging by similar issues other people were having, I want to say it has something to do with what resources you have specified in your /configs/application.ini file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据