我在 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 以从不同的目录运行脚本,比如脚本/作业而不是公共/作业?还有什么我应该做的吗?