bow*_*rae 8 cron cakephp cakephp-2.5
我已阅读以下doc条目:
http://book.cakephp.org/2.0/en/console-and-shells.html
http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html
以及这个问题:
我在尝试实现两个cron作业函数时遇到了麻烦,其中一个与上面列出的Stack Overflow问题完全相同,用于发送测试电子邮件.另一个只是在我的"crons"表中插入一个新行.两者都不起作用,我相信这是我试图称之为cron工作的方式.我不相信我正在使用正确的道路.
控制台/命令/ CronShell.php
class CronShell extends AppShell {
public $uses = array('Cron');
public function trigger() {
$cron = array(
'Cron' => array(
'title' => 'Cron Test'
)
);
$this->Cron->create();
$this->Cron->save($cron);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经使用上面的代码设置了一个CronsController.php作为索引操作的一部分.通过控制器访问代码时工作正常,因此问题在于shell或cron作业.
我曾经按照命令将此方法称为cron作业,没有工作......
***** cd /home1/bhndbrwn/public_html/cake2/app && Console/cake cron trigger
***** cd /home1/bhndbrwn/public_html/cake2/app && Console/cake cronshell trigger
***** cd /home1/bhndbrwn/public_html/cake2/app && Console/cake Cron trigger
***** cd /home1/bhndbrwn/public_html/cake2/app && Console/cake CronShell trigger
***** cd /home1/bhndbrwn/public_html/cake2/app/Console/cake cron trigger
***** cd /home1/bhndbrwn/public_html/cake2/app/Console/cake cronshell trigger
***** cd /home1/bhndbrwn/public_html/cake2/app/Console/cake Cron trigger
***** cd /home1/bhndbrwn/public_html/cake2/app/Console/cake CronShell trigger
Run Code Online (Sandbox Code Playgroud)
同样,我尝试使用以下shell发送测试电子邮件
控制台/命令/ EmailShell.php
App::uses('CakeEmail', 'Network/Email');
class EmailShell extends Shell {
public function main() {
$Email = new CakeEmail();
$Email->template('test', 'default')
->emailFormat('html')
->to(email@domain.com)
->from('no-reply@domain.com')
->subject('Cron Email')
->send();
} // END MAIN FUNCTION
}
Run Code Online (Sandbox Code Playgroud)
我再次尝试了以下命令.对于这些命令中的每一个,我还尝试按照文档的说明删除方法名称"main".
***** cd /home1/bhndbrwn/public_html/cake2/app && Console/cake email main
***** cd /home1/bhndbrwn/public_html/cake2/app && Console/cake emailshell main
***** cd /home1/bhndbrwn/public_html/cake2/app && Console/cake Email main
***** cd /home1/bhndbrwn/public_html/cake2/app && Console/cake EmailShell main
***** cd /home1/bhndbrwn/public_html/cake2/app/Console/cake email main
***** cd /home1/bhndbrwn/public_html/cake2/app/Console/cake emailshell main
***** cd /home1/bhndbrwn/public_html/cake2/app/Console/cake Email main
***** cd /home1/bhndbrwn/public_html/cake2/app/Console/cake EmailShell main
Run Code Online (Sandbox Code Playgroud)
2017年编辑 - 仍然没有工作
我已将我的cron更新为 /home/allfan5/public_html/allfans/app/Console/cake.php -app /home/allfan5/public_html/allfans/app/ test action
我有一个名为TestShell的shell和一个名为"action"的函数.动作函数完全是空的来测试事物(我也尝试了一个函数,我在给用户发电子邮件,但是我遇到了错误所以我创建了一个新的shell和一个完全空的函数,我得到了同样的错误).
我现在收到的错误是
2017-10-14 21:34:02 Error: Fatal Error (64): Cannot use ‘String’ as class name as it is reserved in [/home/allfan5/public_html/allfans/lib/Cake/Utility/String.php, line 25]
2017-10-14 21:34:02 Error: [FatalErrorException] Cannot use ‘String’ as class name as it is reserved
Stack Trace:
#0 /home/allfan5/public_html/allfans/lib/Cake/Error/ErrorHandler.php(203): ErrorHandler::handleFatalError(64, ‘Cannot use ‘Str…’, ‘/home/allfan5/p…’, 25)
#1 /home/allfan5/public_html/allfans/lib/Cake/Core/App.php(929): ErrorHandler::handleError(64, ‘Cannot use ‘Str…’, ‘/home/allfan5/p…’, 25, Array)
#2 /home/allfan5/public_html/allfans/lib/Cake/Core/App.php(902): App::_checkFatalError()
#3 [internal function]: App::shutdown()
#4 {main}
Run Code Online (Sandbox Code Playgroud)
由于shell函数完全为空,我不知道是什么导致这种情况.甚至当我尝试通过电子邮件发送用户时的操作,我复制了代码并从控制器运行它,它工作正常.所以Cake执行或调用shell的方式有问题.
我在PHP 5.4上运行cake 2.5
小智 2
我们使用不同的方式来运行 crons:
在 webroot 目录中,我有一个名为 corn_dispatcher.php 的文件,它是 index.php 文件的副本,但对文件末尾进行了一些修改:
App::uses('调度程序', '路由');
定义('CRON_DISPATCHER',true);
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest($argv[1]), new CakeResponse());
然后我有一个 CronjobController.php 文件,其中包含与各个 cron 相关的函数。还添加了一个 beforeFilter 函数 $this->Auth->allow(); (因此 cron 运行时不会因 ACL 限制而中断)以及删除布局和自动渲染
接下来设置到 cron 的路由。
最后在我的 crontabs 文件中我放入:
1 6 * * * php -f /path-to-webroot/cron_dispatcher.php /routedUrl
另外还有几点需要注意:
我希望这有帮助。
| 归档时间: |
|
| 查看次数: |
1456 次 |
| 最近记录: |