执行 Cron 作业时出现问题

发布于 2024-08-04 10:07:46 字数 14583 浏览 5 评论 0原文

我在 Cake PHP 中做了一个投标网站。我面临的主要问题是我需要在服务器上运行 CRON JOBS。但我不知道为什么它困扰着我。我创建了一个名为“deamons”的控制器,其中有 4 个它的不同操作,我想每分钟在服务器上连续运行,这样我们就可以运行该投标网站的每个用户设置的自动投标程序。 我正在设置的 Cron 作业是...... curl -s -o /dev/null http://www.domain.com/app /webroot/daemons/bidbutler
卷曲 -s -o /dev/null http://www.domain.com/app /webroot/daemons/extend curl -s -o /dev/null http://www.domain.com/app /webroot/daemons/autobid
卷曲 -s -o /dev/null http://www.domain.com/app /webroot/daemons/close

和处理所有内容的控制器附在下面......! 请向我建议一些解决方案,以便

如果专家想要测试它..URL 是 www.domain.com/app/webroot

这是代码...我试图通过 CRONS 运行... !!!

<?php

类 DaemonsController 扩展 AppController {

var $name = 'Daemons';

var $uses = array('Auction', 'Setting');

function beforeFilter(){
    $email='[email protected]';
    $secondemail='[email protected]';
    $mess='It works';
    //@mail($email, 'Test', $mess, "From: ".$secondemail);

    parent::beforeFilter();

    if(!empty($this->Auth)) {
        $this->Auth->allow('bidbutler', 'extend', 'autobid', 'close');
    }
    ini_set('max_execution_time', ($this->appConfigurations['cronTime'] * 60) + 1);
}

/**
 * The function makes the bid butler magic happen
 *
 * @return array Affected Auction
 */
function bidbutler() {

    $this->layout = 'js/ajax';

    $data     = array();
    $setting  = array();
    $auctions = array();

    // Get the bid butler time
    $bidButlerTime = $this->Setting->get('bid_butler_time');

    // Get various settings needed
    $data['bid_debit']               = $this->Setting->get('bid_debit');
    $data['auction_price_increment'] = $this->Setting->get('auction_price_increment');
    $data['auction_time_increment']  = $this->Setting->get('auction_time_increment');
    $data['auction_peak_start']      = $this->Setting->get('auction_peak_start');
    $data['auction_peak_end']        = $this->Setting->get('auction_peak_end');

    $expireTime = time() + ($this->appConfigurations['cronTime'] * 60);

    while (time() < $expireTime) {
        // Formating the conditions
        $conditions = array(
            'Auction.end_time < \''. date('Y-m-d H:i:s', time() + $bidButlerTime). '\'',
            'Auction.closed' => 0,
            'Bidbutler.bids >' => 0
        );

        // Find the bidbutler entry - we get them from the lowest price to the maximum price so that they all run!
        $this->Auction->Bidbutler->contain('Auction');
        $bidbutlers = $this->Auction->Bidbutler->find('all', array('conditions' => $conditions, 'order' => 'rand()', 'fields' => array('Auction.id', 'Auction.start_price', 'Bidbutler.id', 'Bidbutler.minimum_price', 'Bidbutler.maximum_price', 'Bidbutler.user_id'), 'contain' => 'Auction'));

        if(!empty($bidbutlers)) {
            // Walk through bidbutler entries
            foreach($bidbutlers as $bidbutler) {
                if($bidbutler['Bidbutler']['minimum_price'] >= $bidbutler['Auction']['start_price'] &&
                   $bidbutler['Bidbutler']['maximum_price'] < $bidbutler['Auction']['start_price']) {

                    // Add more information
                    $data['auction_id'] = $bidbutler['Auction']['id'];
                    $data['user_id']    = $bidbutler['Bidbutler']['user_id'];
                    $data['bid_butler'] = $bidbutler['Bidbutler']['id'];

                    // Bid the auction
                    $result = $this->Auction->bid($data);
                }
            }
        }
        usleep(900000);
    }
}

/**
 * The function auto extends auctions and bids for an auto bid if neccessary
 *
 * @return array Affected Auction
 */
function extend() {
    $this->layout = 'js/ajax';

    $data     = array();
    $setting  = array();
    $auctions = array();

    $data['bid_debit']               = $this->Setting->get('bid_debit');
    $data['auction_price_increment'] = $this->Setting->get('auction_price_increment');
    $data['auction_time_increment']  = $this->Setting->get('auction_time_increment');
    $data['auction_peak_start']      = $this->Setting->get('auction_peak_start');
    $data['auction_peak_end']        = $this->Setting->get('auction_peak_end');

    $data['isPeakNow']  = $this->isPeakNow();

    $expireTime = time() + ($this->appConfigurations['cronTime'] * 60);

    while (time() < $expireTime) {
        // now check for auto extends
        $auctions = Cache::read('daemons_extend_auctions');
        if(empty($auctions)) {
            $auctions = $this->Auction->find('all', array('contain' => '', 'conditions' => "(Auction.extend_enabled = 1 OR Auction.autobid = 1) AND (Auction.start_price < Auction.minimum_price) AND Auction.winner_id = 0 AND Auction.closed = 0"));
            Cache::write('daemons_extend_auctions', $auctions, '+1 day');
        }

        if(!empty($auctions)) {
            foreach($auctions as $auction) {
                // lets see if we need to extend the auction
                $endTime = strtotime($auction['Auction']['end_time']);
                $extendTime = time() + ($auction['Auction']['time_before_extend']);

                if($extendTime > $endTime) {
                    // lets see if autobid is enabled
                    // autobid will place a bid by a robot if another user is the highest bidder but hasn't meet the minimum price
                    if($auction['Auction']['autobid'] == 1) {
                        if($auction['Auction']['extend_enabled'] == 1) {
                            // lets only bid if the limit is less than te autobid limit when the autobid limit is set
                            if($auction['Auction']['autobid_limit'] > 0) {
                                if($auction['Auction']['current_limit'] <= $auction['Auction']['autobid_limit']) {
                                    $this->Auction->Autobid->check($auction['Auction']['id'], $auction['Auction']['end_time'], $data);
                                }
                            } else {
                                $this->Auction->Autobid->check($auction['Auction']['id'], $auction['Auction']['end_time'], $data);
                            }
                        } else {
                            $bid = $this->Auction->Bid->lastBid($auction['Auction']['id']);
                            // lets set the autobid
                            if(!empty($bid) && ($bid['autobidder'] == 0)) {
                                $this->Auction->Autobid->check($auction['Auction']['id'], $auction['Auction']['end_time'], $data);
                            }
                        }
                    } elseif($auction['Auction']['extend_enabled'] == 1) {
                        unset($auction['Auction']['modified']);
                        $auction['Auction']['end_time'] = date('Y-m-d H:i:s', $endTime + ($auction['Auction']['time_extended']));

                        // lets do a quick check to make sure the new end time isn't less than the current time
                        $newEndTime = strtotime($auction['Auction']['end_time']);
                        if($newEndTime < time()) {
                            $auction['Auction']['end_time'] = date('Y-m-d H:i:s', time() + ($auction['Auction']['time_extended']));
                        }

                        $this->Auction->save($auction);
                    }
                }
            }
        }
        usleep(800000);
    }
}

/**
 * The function auto extends auctions in the last IF the extend function fails
 *
 * @return array Affected Auction
 */
function autobid() {
    $data['bid_debit']               = $this->Setting->get('bid_debit');
    $data['auction_time_increment']  = $this->Setting->get('auction_time_increment');
    $data['auction_price_increment'] = $this->Setting->get('auction_price_increment');
    $data['auction_peak_start']      = $this->Setting->get('auction_peak_start');
    $data['auction_peak_end']        = $this->Setting->get('auction_peak_end');
    $data['isPeakNow']               = $this->isPeakNow();
    $isPeakNow = $this->isPeakNow();

    $expireTime = time() + ($this->appConfigurations['cronTime'] * 60);

    while (time() < $expireTime) {
        // lets start by getting all the auctions that have closed
        $auctions = $this->Auction->find('all', array('fields' => array('Auction.id', 'Auction.peak_only'), 'contain' => '', 'conditions' => "Auction.winner_id = 0 AND Auction.end_time <= '" . date('Y-m-d H:i:s', time() + 4) . "' AND Auction.closed = 0"));

        if(!empty($auctions)) {
            foreach($auctions as $auction) {
                // before we declare this user the winner, lets run some test to make sure the auction can definitely close
                if($this->Auction->checkCanClose($auction['Auction']['id'], $isPeakNow, false) == false) {
                    // lets check to see if the reason we can't close it, is because its now offpeak and this is a peak auction
                    if($auction['Auction']['peak_only'] == 1 && !$isPeakNow) {
                        continue;
                    } else {
                        $this->Auction->Autobid->placeAutobid($auction['Auction']['id'], $data);
                    }
                }
            }
        }
        usleep(900000);
    }
}

/**
 * The function closes the auctions
 *
 * @return array Affected Auction
 */
function close() {
    $expireTime = time() + ($this->appConfigurations['cronTime'] * 60);

    while (time() < $expireTime) {
        // lets start by getting all the auctions that have closed
        $auctions = $this->Auction->find('all', array('contain' => '', 'conditions' => "Auction.winner_id = 0 AND Auction.end_time <= '" . date('Y-m-d H:i:s') . "' AND Auction.closed = 0"));

        if(!empty($auctions)) {
            foreach($auctions as $auction) {
                $isPeakNow = $this->isPeakNow();

                // before we declare this user the winner, lets run some test to make sure the auction can definitely close
                if($this->Auction->checkCanClose($auction['Auction']['id'], $isPeakNow) == false) {
                    // lets check to see if the reason we can't close it, is because its now offpeak and this is a peak auction
                    if($auction['Auction']['peak_only'] == 1 && !$isPeakNow) {
                        $peak = $this->nonPeakDates();

                        //Calculate how many seconds auction will end after peak end
                        $seconds_after_peak = strtotime($auction['Auction']['end_time']) - strtotime($peak['peak_end']);
                        $end_time = strtotime($peak['peak_start']) + $seconds_after_peak;

                        $auction['Auction']['end_time'] = date('Y-m-d H:i:s', $end_time);
                        $this->Auction->save($auction);

                    } else {
                        // lets check just how far ago this auction closed, and either place an autobid or extend the time
                        $data['auction_time_increment']  = $this->Setting->get('auction_time_increment');

                        $newEndTime = strtotime($auction['Auction']['end_time']);
                        if($newEndTime < time() - $data['auction_time_increment']) {
                            $auction['Auction']['end_time'] = date('Y-m-d H:i:s', time() + ($auction['Auction']['time_extended']));
                            $this->Auction->save($auction);
                        } else {
                            //lets extend it by placing an autobid
                            $data['bid_debit']               = $this->Setting->get('bid_debit');
                            $data['auction_price_increment'] = $this->Setting->get('auction_price_increment');
                            $data['auction_peak_start']      = $this->Setting->get('auction_peak_start');
                            $data['auction_peak_end']        = $this->Setting->get('auction_peak_end');
                            $data['isPeakNow']               = $this->isPeakNow();

                            $this->Auction->Autobid->placeAutobid($auction['Auction']['id'], $data);
                        }
                    }
                    continue;
                }

                $bid = $this->Auction->Bid->find('first', array('conditions' => array('Bid.auction_id' => $auction['Auction']['id']), 'order' => array('Bid.id' => 'desc')));
                if(!empty($bid)) {
                    if($bid['User']['autobidder'] == 0) {
                        // send the email to the winner
                        $data['Auction']               = $auction['Auction'];
                        $data['Bid']                   = $bid['Bid'];
                        $data['User']                  = $bid['User'];
                        $data['to']                    = $data['User']['email'];
                        $data['subject']               = sprintf(__('%s - You have won an auction', true), $this->appConfigurations['name']);
                        $data['template']              = 'auctions/won_auction';
                        $this->_sendEmail($data);

                        $auction['Auction']['status_id'] = 1;
                    }

                    $auction['Auction']['winner_id'] = $bid['Bid']['user_id'];
                }
                unset($auction['Auction']['modified']);
                $auction['Auction']['closed'] = 1;
                $this->Auction->save($auction);
            }
        }
        usleep(900000);
    }
}

} ?>

i have done a bidding site in Cake PHP.The main problem I am facing is I need to run CRON JOBS on the server.But I dont' know why it is bugging me.I have craeted a controller called 'deamons' and there 4 different actions of it,which I want to run continuously on the server every minute,so that we can run the Autobidder set by each user of that bidding site.
The Cron Jobs I am setting up are...
curl -s -o /dev/null http://www.domain.com/app/webroot/daemons/bidbutler
curl -s -o /dev/null http://www.domain.com/app/webroot/daemons/extend
curl -s -o /dev/null http://www.domain.com/app/webroot/daemons/autobid
curl -s -o /dev/null http://www.domain.com/app/webroot/daemons/close

and the the controller which is handling all the stuff is attached below....!!!
Please suggest me some solution to this so that

If the experts wants to test it..the URL is www.domain.com/app/webroot

And here is the code...which I am trying to run through the CRONS...!!!

<?php

class DaemonsController extends AppController {

var $name = 'Daemons';

var $uses = array('Auction', 'Setting');

function beforeFilter(){
    $email='[email protected]';
    $secondemail='[email protected]';
    $mess='It works';
    //@mail($email, 'Test', $mess, "From: ".$secondemail);

    parent::beforeFilter();

    if(!empty($this->Auth)) {
        $this->Auth->allow('bidbutler', 'extend', 'autobid', 'close');
    }
    ini_set('max_execution_time', ($this->appConfigurations['cronTime'] * 60) + 1);
}

/**
 * The function makes the bid butler magic happen
 *
 * @return array Affected Auction
 */
function bidbutler() {

    $this->layout = 'js/ajax';

    $data     = array();
    $setting  = array();
    $auctions = array();

    // Get the bid butler time
    $bidButlerTime = $this->Setting->get('bid_butler_time');

    // Get various settings needed
    $data['bid_debit']               = $this->Setting->get('bid_debit');
    $data['auction_price_increment'] = $this->Setting->get('auction_price_increment');
    $data['auction_time_increment']  = $this->Setting->get('auction_time_increment');
    $data['auction_peak_start']      = $this->Setting->get('auction_peak_start');
    $data['auction_peak_end']        = $this->Setting->get('auction_peak_end');

    $expireTime = time() + ($this->appConfigurations['cronTime'] * 60);

    while (time() < $expireTime) {
        // Formating the conditions
        $conditions = array(
            'Auction.end_time < \''. date('Y-m-d H:i:s', time() + $bidButlerTime). '\'',
            'Auction.closed' => 0,
            'Bidbutler.bids >' => 0
        );

        // Find the bidbutler entry - we get them from the lowest price to the maximum price so that they all run!
        $this->Auction->Bidbutler->contain('Auction');
        $bidbutlers = $this->Auction->Bidbutler->find('all', array('conditions' => $conditions, 'order' => 'rand()', 'fields' => array('Auction.id', 'Auction.start_price', 'Bidbutler.id', 'Bidbutler.minimum_price', 'Bidbutler.maximum_price', 'Bidbutler.user_id'), 'contain' => 'Auction'));

        if(!empty($bidbutlers)) {
            // Walk through bidbutler entries
            foreach($bidbutlers as $bidbutler) {
                if($bidbutler['Bidbutler']['minimum_price'] >= $bidbutler['Auction']['start_price'] &&
                   $bidbutler['Bidbutler']['maximum_price'] < $bidbutler['Auction']['start_price']) {

                    // Add more information
                    $data['auction_id'] = $bidbutler['Auction']['id'];
                    $data['user_id']    = $bidbutler['Bidbutler']['user_id'];
                    $data['bid_butler'] = $bidbutler['Bidbutler']['id'];

                    // Bid the auction
                    $result = $this->Auction->bid($data);
                }
            }
        }
        usleep(900000);
    }
}

/**
 * The function auto extends auctions and bids for an auto bid if neccessary
 *
 * @return array Affected Auction
 */
function extend() {
    $this->layout = 'js/ajax';

    $data     = array();
    $setting  = array();
    $auctions = array();

    $data['bid_debit']               = $this->Setting->get('bid_debit');
    $data['auction_price_increment'] = $this->Setting->get('auction_price_increment');
    $data['auction_time_increment']  = $this->Setting->get('auction_time_increment');
    $data['auction_peak_start']      = $this->Setting->get('auction_peak_start');
    $data['auction_peak_end']        = $this->Setting->get('auction_peak_end');

    $data['isPeakNow']  = $this->isPeakNow();

    $expireTime = time() + ($this->appConfigurations['cronTime'] * 60);

    while (time() < $expireTime) {
        // now check for auto extends
        $auctions = Cache::read('daemons_extend_auctions');
        if(empty($auctions)) {
            $auctions = $this->Auction->find('all', array('contain' => '', 'conditions' => "(Auction.extend_enabled = 1 OR Auction.autobid = 1) AND (Auction.start_price < Auction.minimum_price) AND Auction.winner_id = 0 AND Auction.closed = 0"));
            Cache::write('daemons_extend_auctions', $auctions, '+1 day');
        }

        if(!empty($auctions)) {
            foreach($auctions as $auction) {
                // lets see if we need to extend the auction
                $endTime = strtotime($auction['Auction']['end_time']);
                $extendTime = time() + ($auction['Auction']['time_before_extend']);

                if($extendTime > $endTime) {
                    // lets see if autobid is enabled
                    // autobid will place a bid by a robot if another user is the highest bidder but hasn't meet the minimum price
                    if($auction['Auction']['autobid'] == 1) {
                        if($auction['Auction']['extend_enabled'] == 1) {
                            // lets only bid if the limit is less than te autobid limit when the autobid limit is set
                            if($auction['Auction']['autobid_limit'] > 0) {
                                if($auction['Auction']['current_limit'] <= $auction['Auction']['autobid_limit']) {
                                    $this->Auction->Autobid->check($auction['Auction']['id'], $auction['Auction']['end_time'], $data);
                                }
                            } else {
                                $this->Auction->Autobid->check($auction['Auction']['id'], $auction['Auction']['end_time'], $data);
                            }
                        } else {
                            $bid = $this->Auction->Bid->lastBid($auction['Auction']['id']);
                            // lets set the autobid
                            if(!empty($bid) && ($bid['autobidder'] == 0)) {
                                $this->Auction->Autobid->check($auction['Auction']['id'], $auction['Auction']['end_time'], $data);
                            }
                        }
                    } elseif($auction['Auction']['extend_enabled'] == 1) {
                        unset($auction['Auction']['modified']);
                        $auction['Auction']['end_time'] = date('Y-m-d H:i:s', $endTime + ($auction['Auction']['time_extended']));

                        // lets do a quick check to make sure the new end time isn't less than the current time
                        $newEndTime = strtotime($auction['Auction']['end_time']);
                        if($newEndTime < time()) {
                            $auction['Auction']['end_time'] = date('Y-m-d H:i:s', time() + ($auction['Auction']['time_extended']));
                        }

                        $this->Auction->save($auction);
                    }
                }
            }
        }
        usleep(800000);
    }
}

/**
 * The function auto extends auctions in the last IF the extend function fails
 *
 * @return array Affected Auction
 */
function autobid() {
    $data['bid_debit']               = $this->Setting->get('bid_debit');
    $data['auction_time_increment']  = $this->Setting->get('auction_time_increment');
    $data['auction_price_increment'] = $this->Setting->get('auction_price_increment');
    $data['auction_peak_start']      = $this->Setting->get('auction_peak_start');
    $data['auction_peak_end']        = $this->Setting->get('auction_peak_end');
    $data['isPeakNow']               = $this->isPeakNow();
    $isPeakNow = $this->isPeakNow();

    $expireTime = time() + ($this->appConfigurations['cronTime'] * 60);

    while (time() < $expireTime) {
        // lets start by getting all the auctions that have closed
        $auctions = $this->Auction->find('all', array('fields' => array('Auction.id', 'Auction.peak_only'), 'contain' => '', 'conditions' => "Auction.winner_id = 0 AND Auction.end_time <= '" . date('Y-m-d H:i:s', time() + 4) . "' AND Auction.closed = 0"));

        if(!empty($auctions)) {
            foreach($auctions as $auction) {
                // before we declare this user the winner, lets run some test to make sure the auction can definitely close
                if($this->Auction->checkCanClose($auction['Auction']['id'], $isPeakNow, false) == false) {
                    // lets check to see if the reason we can't close it, is because its now offpeak and this is a peak auction
                    if($auction['Auction']['peak_only'] == 1 && !$isPeakNow) {
                        continue;
                    } else {
                        $this->Auction->Autobid->placeAutobid($auction['Auction']['id'], $data);
                    }
                }
            }
        }
        usleep(900000);
    }
}

/**
 * The function closes the auctions
 *
 * @return array Affected Auction
 */
function close() {
    $expireTime = time() + ($this->appConfigurations['cronTime'] * 60);

    while (time() < $expireTime) {
        // lets start by getting all the auctions that have closed
        $auctions = $this->Auction->find('all', array('contain' => '', 'conditions' => "Auction.winner_id = 0 AND Auction.end_time <= '" . date('Y-m-d H:i:s') . "' AND Auction.closed = 0"));

        if(!empty($auctions)) {
            foreach($auctions as $auction) {
                $isPeakNow = $this->isPeakNow();

                // before we declare this user the winner, lets run some test to make sure the auction can definitely close
                if($this->Auction->checkCanClose($auction['Auction']['id'], $isPeakNow) == false) {
                    // lets check to see if the reason we can't close it, is because its now offpeak and this is a peak auction
                    if($auction['Auction']['peak_only'] == 1 && !$isPeakNow) {
                        $peak = $this->nonPeakDates();

                        //Calculate how many seconds auction will end after peak end
                        $seconds_after_peak = strtotime($auction['Auction']['end_time']) - strtotime($peak['peak_end']);
                        $end_time = strtotime($peak['peak_start']) + $seconds_after_peak;

                        $auction['Auction']['end_time'] = date('Y-m-d H:i:s', $end_time);
                        $this->Auction->save($auction);

                    } else {
                        // lets check just how far ago this auction closed, and either place an autobid or extend the time
                        $data['auction_time_increment']  = $this->Setting->get('auction_time_increment');

                        $newEndTime = strtotime($auction['Auction']['end_time']);
                        if($newEndTime < time() - $data['auction_time_increment']) {
                            $auction['Auction']['end_time'] = date('Y-m-d H:i:s', time() + ($auction['Auction']['time_extended']));
                            $this->Auction->save($auction);
                        } else {
                            //lets extend it by placing an autobid
                            $data['bid_debit']               = $this->Setting->get('bid_debit');
                            $data['auction_price_increment'] = $this->Setting->get('auction_price_increment');
                            $data['auction_peak_start']      = $this->Setting->get('auction_peak_start');
                            $data['auction_peak_end']        = $this->Setting->get('auction_peak_end');
                            $data['isPeakNow']               = $this->isPeakNow();

                            $this->Auction->Autobid->placeAutobid($auction['Auction']['id'], $data);
                        }
                    }
                    continue;
                }

                $bid = $this->Auction->Bid->find('first', array('conditions' => array('Bid.auction_id' => $auction['Auction']['id']), 'order' => array('Bid.id' => 'desc')));
                if(!empty($bid)) {
                    if($bid['User']['autobidder'] == 0) {
                        // send the email to the winner
                        $data['Auction']               = $auction['Auction'];
                        $data['Bid']                   = $bid['Bid'];
                        $data['User']                  = $bid['User'];
                        $data['to']                    = $data['User']['email'];
                        $data['subject']               = sprintf(__('%s - You have won an auction', true), $this->appConfigurations['name']);
                        $data['template']              = 'auctions/won_auction';
                        $this->_sendEmail($data);

                        $auction['Auction']['status_id'] = 1;
                    }

                    $auction['Auction']['winner_id'] = $bid['Bid']['user_id'];
                }
                unset($auction['Auction']['modified']);
                $auction['Auction']['closed'] = 1;
                $this->Auction->save($auction);
            }
        }
        usleep(900000);
    }
}

}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生百味 2024-08-11 10:07:46

CakePHP 运行 crons 的方法是构建您自己的 shell 来执行任务。 Shell 允许您通过命令提示符完全访问所有控制器。开始时请务必阅读此文档:

http://book.cakephp.org /view/108/The-CakePHP-Console

它向您展示了如何构建自己的 shell (app/vendors/shells/)、如何将 shell 组织成任务以及如何将 shell 作为 cron 正确运行工作。

我的做法与文档描述的略有不同。我的 cron 语句如下所示:

* * * * * (cd /path/to/my/cake/app; sh ../cake/console/cake daily;) 1> /dev/null 2>&1

从那里我只有一个名为 app/vendors/shells/daily.php 的 shell,

<?php
class DailyShell extends Shell {

    var $uses = array('User');

        function main() {

                $this->User->processDailyTasks();

        }
}
?>

这比在 cron 作业中使用curl 更好、更稳定。

The CakePHP way to run crons is to build your own shells to do the tasks. Shells allows you full access to all of your controllers through the command prompt. Be sure to read this documentation when starting:

http://book.cakephp.org/view/108/The-CakePHP-Console

It shows you how to build your own shells (app/vendors/shells/), how to organize your shells into tasks, and how to properly run your shell as a cron job.

I do it a slightly different way than the documentation describes. My cron statement looks like:

* * * * * (cd /path/to/my/cake/app; sh ../cake/console/cake daily;) 1> /dev/null 2>&1

From there I simply have a shell called app/vendors/shells/daily.php

<?php
class DailyShell extends Shell {

    var $uses = array('User');

        function main() {

                $this->User->processDailyTasks();

        }
}
?>

This is far better and more stable than using curl in a cron job.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文