All day spent trying to figure it out.
cronjob cpanel command:
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');
}
}
}
}
}
}
}
I get in email after cron runs “class CI_controller not found when running cronjob”
Any ideas or help why is this happening? Am I writing the cron job wrong? Using codeigniter.
2
Answers
You have to call depending on your path “/home/folder”:
/usr/local/bin/php -d max_execution_time=36000 -d memory_limit=512M /home/folder/public_html/index.php cronjob transactions
so index.php calls cronjob class and transaction function
you probably need $route[‘cronjob/(:any)’] = “cronjob/$1”; in the routes
You should call like following,
add following code in routes.php
now add following
command
in cpanel cronjobReplace the
example.com
withyour domain name.