我在Zend Framework中发现了很多与目录结构和cron作业相关的帖子,但没有明确答案:(
我有以下代码来创建发送电子邮件的作业。只要脚本(emailNotification.php)位于公共目录中的/ jobs下,就可以正常工作。
public function emailAction() {
$request = $this->getRequest();
if ($request->isPost()) {
$emailFrom = $request->getPost('emailFrom');
$messageFrom = $request->getPost('messageFrom');
$subject = $request->getPost('Sub');
$emailTo = $request->getPost('emailTo');
// create a queued job
date_default_timezone_set('UTC');
$q = new ZendJobQueue();
$ts = date('Y-m-d H:i:s', time()+30);
$id=$q->createHttpJob('jobs/emailNotification.php',array('emailFrom'=>$emailFrom,
'messageFrom'=>$messageFrom,'subject'=>$subject,
'emailTo'=>$emailTo),
array('name'=>'email notification using a single job execution scheduled to run after 30 seconds','schedule_time'=>$ts));
if(!$id)
$this->_helper->json(array('status' => 'success', 'message' => "Queued job didn't work."));
$this->_helper->json(array('status' => 'success', 'message' => "Email sent successfully."));
} // request->isPost()
}// function emailAction
我的目录结构是ZF创建的默认结构:
[MyProject]
[application]
[data]
[docs]
[library]
[public]
index.php
[scripts]
如何修改createHttpJob以从其他目录运行脚本,例如脚本/作业而不是公共/作业?还有什么我应该做的吗?
答案 0 :(得分:0)
这实际上取决于你如何调用cron作业,以及你在脚本开始时做了多少引导(如果有的话)。我会将您的代码更改为:
$id=$q->createHttpJob(APPLICATION_PATH.'/../scripts/jobs/emailNotification.php', [...]
首先,然后您需要做的就是确保在您的cron脚本中设置了APPLICATION_PATH。