CakePHP 2.X Cron工作不起作用
2017年底部编辑
我已阅读以下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 以及这个问题: Creating Cron Jobs in CakePHP 2.x 我在尝试实现两个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); } } 我已经使用上面的代码设置了一个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 同样,我尝试使用以下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 } 我再次尝试了以下命令.对于这些命令中的每一个,我还尝试按照文档的说明删除方法名称“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 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,25,Array) #2 /home/allfan5/public_html/allfans/lib/Cake/Core/App.php(902): App::_checkFatalError() #3 [internal function]: App::shutdown() #4 {main} 由于shell函数完全为空,我不知道是什么导致这种情况.甚至当我尝试通过电子邮件发送用户时的动作,我复制了代码并从控制器运行它,它工作正常.所以Cake执行或调用shell的方式有问题. 我在PHP 5.4上运行cake 2.5
我们使用不同的运行方式:
在webroot目录中,我有一个名为corn_dispatcher.php的文件,它是index.php文件的副本,但对文件末尾进行了一些修改: App :: uses(‘Dispatcher’,’Routing’); 然后我有一个CronjobController.php文件,其中包含与各个crons相关的函数. 接下来设置通往crons的路线. 最后在我的crontabs文件中,我把: 1 6 * * * php -f /path-to-webroot/cron_dispatcher.php / routedUrl 还有一点需要注意: >你可能需要运行php表单的完整路径,而不是像我上面那样. 我希望有所帮助. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |