【问题标题】:class CI_controller not found when running cronjob运行 cronjob 时找不到类 CI_controller
【发布时间】:2018-10-15 01:07:04
【问题描述】:

花了一整天的时间试图弄清楚。

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。

【问题讨论】:

  • php -q /home/cesspool/public_html/index.php Cronjob 事务这也不起作用

标签: php codeigniter cron cpanel


【解决方案1】:

你必须根据你的路径“/home/folder”调用:

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

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

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

【讨论】:

    【解决方案2】:

    你应该像下面这样调用,

    routes.php

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

    现在在 cpanel cronjob 中添加以下 command

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

    example.com 替换为您的域名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-11
      • 2012-12-08
      • 2012-12-01
      • 1970-01-01
      • 2013-11-04
      • 1970-01-01
      • 2013-02-18
      相关资源
      最近更新 更多