【发布时间】: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