运行cronjob时找不到类CI_controller

时间:2018-05-04 13:58:41

标签: php codeigniter cron cpanel

整天都在努力弄明白。

cronjob cpanel命令:  php -q /home/domain/public_html/application/controllers/Cronjob.php

cronjob.php

<?php


class Cronjob extends CI_Controller {

public function __construct(){
    parent::__construct();
}

public function transactions(){
    $addresses = $this->db->get_where('bitcoin_addresses')->result();

    foreach ($addresses as $key => $value) {
        $id             = $value->id;
        $owner_id       = $value->owner_id;
        $btc_addresses  = $value->btc_address;
        $btc_label      = $value->btc_label;

        $transactions = $this->Block->get_transactions($owner_id);

        foreach ($transactions as $k => $v) {

            $tx = $this->Block->get_transaction($owner_id, $v->txid);

            if(@$tx[0]->status < 2){
                if(!$tx){
                    //يتيح إضافة هذه المعاملة إلى قاعدة البيانات
                    $data = array(
                        'owner_id'      => $owner_id,
                        'txid'          => $v->txid,
                        'amount'        => $v->amounts_received[0]->amount,
                        'confirmations' => $v->confirmations,
                        'time'          => $v->time,
                        'status'        => 1
                    );
                    $this->db->insert('bitcoin_transactions', $data);
                }else{

                    $this->db->set('confirmations', $v->confirmations, true);

                    $update_account = false;
                    if($v->confirmations >= 1 && $tx[0]->status == '1'){
                        $this->db->set('status', 2, true);
                        $update_account = true;
                    }

                    $this->db->where('txid', $v->txid);
                    $this->db->update('bitcoin_transactions'); 

                    if($update_account){
                        $btc_price = json_decode(file_get_contents('https://blockchain.info/nl/ticker'));

                        $btc_price = $btc_price->USD->last;
                        $usd_value = round($btc_price * $v->amounts_received[0]->amount, 2);
                        $this->db->set('balance',  $this->ion_auth->user($owner_id)->row()->balance + $usd_value, true);
                        $this->db->where('id', $owner_id);
                        $this->db->update('users');
                    }
                }
            }
        }
    }
}
}

我在cron运行后收到电子邮件“运行cronjob时找不到类CI_controller” 任何想法或帮助为什么会发生这种情况?我写的cron工作错了吗?使用codeigniter。

2 个答案:

答案 0 :(得分:0)

您必须根据路径“/ home / folder”拨打电话:

/ usr / local / bin / php -d max_execution_time = 36000 -d memory_limit = 512M /home/folder/public_html/index.php cronjob transactions

所以index.php调用cronjob类和事务函数

你可能需要$ route ['cronjob /(:any)'] =“cronjob / $ 1”;在路线

答案 1 :(得分:0)

你应该像下面这样打电话,

routes.php

中添加以下代码
$route['transactions'] = 'cronjob/transactions';

现在在cpanel cronjob中添加以下command

wget -O - http://example.com/transactions >/dev/null 2>&1

example.com替换为您的域名。