脚本宝典收集整理的这篇文章主要介绍了Cron Dispatcher CakePHP 2.0,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我收到的错误是这样的:
Undefined VARiable: argc [APP/webroot/cron_dispatcher.PHP,line 83
这是我的app / webroot /目录中cron_dispatcher.PHP文件的底部.
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.PHP')) { trigger_error("CakePHP core Could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.PHP. IT should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.",E_USER_ERROR); } if (isset($_GET['url']) @R_406_315@ $_GET['url'] === 'favicon.ico') { return; } else { define('CRON_DISPATCHER',true); if($argc >= 2) { $Dispatcher= new Dispatcher(); $Dispatcher->dispatch($argv[1]); } }
我找不到这些变量($argv和$argc)的定义.它们未在dispatcher.PHP文件本身的任何位置定义.我搜索谷歌无济于事.我不是百分百确定Dispatcher的工作原理,但是我们将非常感谢任何帮助.谢谢.
在新的CakePHP 2.0.5中,您将在webroot文件夹中找到index.PHP:
复制此文件并将其命名为cron_dispatcher.PHP,并将其放入同一目录(webroot)
$Dispatcher = new Dispatcher(); $Dispatcher->dispatch(new CakeRequest(),new CakeResponse(array('charset' => Configure::read('App.encoding'))));
define('CRON_DISPATCHER',true); $Dispatcher = new Dispatcher(); $Dispatcher->dispatch(new CakeRequest($argv[1]),new CakeResponse(array('charset' => Configure::read('App.encoding'))));
你在这里做了两件事:将CRON_DISPATCHER设置为true,并传递环境变量($argv [1]).
在您的控制器中,在执行任何其他操作之前添加此行:
if (!defined('CRON_DISPATCHER')) { $this->redirect('/'); exit(); }
这将确保人们访问yoursite.COM/controller/cronaction将无法运行您的脚本.
<Files "cron_dispatcher.PHP"> Order deny,allow Deny From all </Files>
这将确保人们访问yoursite.com/cron_dispatcher.PHP将无法运行它.
现在使用类似命令设置cron作业:
PHP /home/yoursite/public_htML/cakePHP/app/webroot/cron_dispatcher.PHP /controller/cronjobaction
以上是脚本宝典为你收集整理的Cron Dispatcher CakePHP 2.0全部内容,希望文章能够帮你解决Cron Dispatcher CakePHP 2.0所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。