【问题标题】:Where do I point my Cron job path?我在哪里指出我的 Cron 工作路径?
【发布时间】:2015-02-05 23:45:41
【问题描述】:

我正在使用 Zend Framework 2 并希望运行 Cron 作业。我已经构建了一个模块来处理我所有的 cron 作业。在我的 CronController 中,我想运行一个动作。

Cron 控制器

   public function indexAction() 
{
     $appointmentEmail = new ReminderAppointmentEmail;                  
     $appointmentEmail->SendReminderEmail();
}

Module.config

'console' => array(
    'router' => array(
        'routes' => array(
            'cron' => array(
                'options' => array(
                    'route'    => 'sendTest',
                    'defaults' => array(
                        'controller' => 'Cron\Controller\Cron',
                        'action' => 'index'
                    )
                )
            )
        )
    )
)

我在哪里指向 cron 作业路径?是控制器php还是索引php?我在这两个方面都遇到了麻烦。

以下是我的 cron 代码(根据其他堆栈溢出帖子)

usr/bin/php -q /home/**user**/public_html/public/index.php sendTest

【问题讨论】:

  • 它应该基于stackoverflow.com/questions/19768948/…运行。但是它似乎正在运行实际的网站索引(基于系统生成电子邮件)
  • 听起来 ZF 没有正确检测到它是 CLI 请求。您是否在生产服务器或本地计算机上遇到此问题?同一台机器上php -r "echo PHP_SAPI;" 的输出是什么?
  • 将该行添加到 cron 代码或 zf2 操作中?它在生产服务器上。
  • cgi-fcgi 是输出
  • 好的 - 你能看看 /usr/bin 中是否有一个单独的 PHP 二进制文件用于 PHP cli 吗?例如。查看是否存在类似/usr/bin/php-cli/usr/bin/php5-cli 的内容。

标签: php zend-framework cron zend-framework2


【解决方案1】:

根据您评论中的信息,您应该能够将您的 cron 命令更改为:

/usr/bin/php-cli /home/**user**/public_html/public/index.php sendTest

它应该可以按预期工作(或者至少给你一个更好的错误信息)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    相关资源
    最近更新 更多