php - 运行 cronjob 时找不到类 CI_controller
问题描述
一整天都在试图弄清楚。
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作业吗?使用代码点火器。
解决方案
你应该像下面这样调用,
在routes.php中添加以下代码
$route['transactions'] = 'cronjob/transactions';
command
现在在 cpanel cronjob 中添加以下内容
wget -O - http://example.com/transactions >/dev/null 2>&1
替换为您的example.com
域名。
推荐阅读
- vuetify.js - 当我为 navdrawers 设置不同的设置时,为选项卡设置路由器视图
- android - Android:如何拦截 HTTPURLConnection 网络调用?
- sql - 部门表上的更新触发器,如果特定部门已停用,则将员工设置为活动状态
- android - 为 for 循环中绘制的每条路径设置动画
- android - 在自定义列表器服务中使用 ActivityContext
- android - facebook 的原生广告高级(统一)中介点击问题
- javascript - Generate a button and bind it to another onclick function
- json - Azure DataFactory 无法使用定义检查版本
- google-drive-api - 通过 python 使用 Google Drive API V3 获取 Google Drive 文件所有者的电子邮件地址
- opencv - 如何估计两个相似图像之间的变换矩阵