Cronjob not work well

Username (e.g. epiz_XXX) or Website URL

https://autolend.cf

Other Information

My cronjob cannot work well.
cronjob set to run every 10 min:
http://autolend.cf/crons/TenMinuteCron.php

In this cronjob, I set a check message that if it runs it will record the result in mySQL database. I found that it did not work for every 10 minutes, but works randomly…

How to fix this?

Maybe can you share the contents of TenMinuteCron.php for debugging?

(Just censor all sensitive data)

If im not mistaken, it seems that the problem is on PHP code.

1 Like

Cron Job isn’t very efficient here. That may be the problem.

The Code’s Here:

<?php
/*//////////////////////////////
  10 Minute Cron Job				
  Should be run very 10 minutes	
  Ex: 						
  01,11,21,31,41,51 * * * * wget -qO- http://yoursite.com/MarginBot/TenMinuteCron.php >/dev/null 2>&1
////////////////////////////////*/

// file configs //
require_once("../inc/config.php");

// db connectors and functions //
require_once("../inc/database.php");
$db = new Database();

// account functions //
require_once("../inc/Accounts.php");


require_once('../inc/ExchangeAPIs/bitfinex.php');

// * Get All Active BFX Accounts     * //
// * Create Account Objects for them * //

// check that the crons database exists //
$cronsTableSQL = '
	CREATE TABLE IF NOT EXISTS `'.$config['db']['prefix'].'CronRuns` (
	  `id` int(11) NOT NULL AUTO_INCREMENT,
	  `cron_id` tinyint(1) NOT NULL,
	  `lastrun` datetime NOT NULL,
	  `details` varchar(256) NOT NULL,
	  PRIMARY KEY (`id`)
	)';
$rt = $db->iquery($cronsTableSQL);


$userIds = $db->query("SELECT id from `".$config['db']['prefix']."Users` WHERE status >= '1' AND ( status != '2' AND  status != '8' )  ORDER BY id ASC");
foreach($userIds as $uid){
	/* Run the bot to update all pending loans according to account settings */	
	$act = new Accounts($uid['id']);
	$bfx = new Bitfinex($uid['id'], $act->apiKey, $act->apiSec);
	$bfx->bitfinex_updateMyLends();
	// mark it in the crons table so we know its working
	$cronUpdates = $db->iquery("INSERT into `".$config['db']['prefix']."CronRuns` (`cron_id`, `lastrun`, `details`) VALUES ('2', NOW(), 'Updated User ".$uid['id']." Current Loans')");	
}


?>

The cron scheduling is a bit… weird. Can you please try setting the corn job up again, but this time with “Hours” set to 1 and see what that does to the schedule?

2 Likes

But I need this cron to be done once per 10 min. I use cronjob.org right now and it works.

Like I said: the scheduling is weird and many not do what you expect.

What I meant is that if you change the hours to 1, then it may just work the way you wanted to. Does it make sense? Not at all. But that’s what it is.

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.