2013-08-26 25 views
1

我遵循本網站的指示:http://colorblindprogramming.com/cronjobs-in-cakephp-2-in-5-steps,但我的cronjob不起作用。CakePHP 2.3 - cron調度程序

這是我/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控制器:

<?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 /應用/ cron_dispatcher。 php/cron/delete_spam

沒有任何反應,Cron無法正常工作。爲什麼???

+0

我有一個類似的問題,嘗試PHP /home/somepath/www/app/cron_dispatcher.php這可能是不正確的,但它的價值去:) –

+0

謝謝,但不幸的是,這不是我的問題的解決方案。 – user2580714

+0

可能的重複[如何在蛋糕php中設置cronjobs?](http://stackoverflow.com/questions/13949539/how-to-setup-cronjobs-in-cake-php) – AD7six

回答

8

忽略該頁面,它給出了錯誤的建議,並提出了一個糟糕的體系結構。這只是錯誤的。

相反,你應該使用一個殼。 See the page in the CakePHP book about shells

您的應用程序如果編寫得當,應該在模型中包含所有數據處理和操作代碼。通過這個代碼很容易在控制器和外殼之間共享。

+0

感謝您的回覆。我會接受你的建議 – user2580714

+0

請接受這個答案 –