CakePHP 2.3 - cron调度程序 [英] CakePHP 2.3 - cron dispatcher

查看:141
本文介绍了CakePHP 2.3 - cron调度程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照此网站的指示操作: http://colorblindprogramming.com / cronjobs-in-cakephp-2-in-5-steps ,但我的cronjob不工作。

I followed instructions from this website: http://colorblindprogramming.com/cronjobs-in-cakephp-2-in-5-steps , but my cronjob does not work.

这是我的/app/cron_dispatcher.php :

This is my /app/cron_dispatcher.php:

<?php

if (!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
}

if (!defined('ROOT')) {
       define('ROOT', dirname(dirname(__FILE__)));
   }

   if (!defined('APP_DIR')) {
       define('APP_DIR', basename(dirname(__FILE__)));
   }
if (!defined('WEBROOT_DIR')) {
    define('WEBROOT_DIR', basename(dirname(__FILE__)));
}
if (!defined('WWW_ROOT')) {
    define('WWW_ROOT', dirname(__FILE__) . DS);
}

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
    if (function_exists('ini_set')) {
        ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
    }
    if (!include('Cake' . DS . 'bootstrap.php')) {
        $failed = true;
    }
} else {
    if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {
        $failed = true;
    }
}
if (!empty($failed)) {
    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);
}

App::uses('Dispatcher', 'Routing');
define('CRON_DISPATCHER',true);
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(
new CakeRequest($argv[1]),
new CakeResponse());

这是我的cron控制器:

And this is my cron controller:

<?php
App::uses('AppController', 'Controller');
class CronController extends AppController {

    public $name = 'Cron';
    public $uses = array('NewsletterUser'); 

    public function beforeFilter() {
        parent::beforeFilter();
        $this->layout=null;
    }

    public function delete_spam() {
        // Check the action is being invoked by the cron dispatcher 
        if (!defined('CRON_DISPATCHER')) { $this->redirect('/'); exit(); } 

        //no view
        $this->autoRender = false;       

$this->NewsletterUser->deleteAll(array("NOT" => array('NewsletterUser.active' => 1)), false);  
    }
}

cron调用:php / home / somepath / public_html / app / cron_dispatcher.php / cron / delete_spam

cron call: php /home/somepath/public_html/app/cron_dispatcher.php /cron/delete_spam

没有什么发生,Cron不工作。 WHY

Nothing happens, Cron does not work. WHY???

推荐答案

忽略该页面,它提供错误的建议,这是错误的。

Ignore that page, it gives false advice and proposes a bad architecture. It's just wrong.

相反,你应该使用shell。 请参阅CakePHP书中关于shell的页面

Instead you should use a shell for that. See the page in the CakePHP book about shells.

您的应用程序如果正确写入,应该在模型中包含所有数据处理和操作代码。通过这个代码是很容易在控制器和shell之间共享。

Your application, if properly written, should have all data processing and manipulation code inside a model. By this the code is very easy to share between a controller and a shell.

这篇关于CakePHP 2.3 - cron调度程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆