use memcache object method instead of low level method (#234)

This commit is contained in:
Johan Dufour 2018-03-06 13:26:03 +01:00 committed by Tanguy Pruvot
parent 8c85b95220
commit 1e06755a74
6 changed files with 37 additions and 41 deletions

View file

@ -4,7 +4,7 @@ function send_email_alert($name, $title, $message, $t=10)
{ {
// debuglog(__FUNCTION__); // debuglog(__FUNCTION__);
$last = memcache_get(controller()->memcache->memcache, "last_email_sent_$name"); $last = controller()->memcache->get("last_email_sent_$name");
if($last + $t*60 > time()) return; if($last + $t*60 > time()) return;
debuglog("mail('".YAAMP_ADMIN_EMAIL."', $title, ...)"); debuglog("mail('".YAAMP_ADMIN_EMAIL."', $title, ...)");
@ -12,7 +12,7 @@ function send_email_alert($name, $title, $message, $t=10)
$b = mail(YAAMP_ADMIN_EMAIL, $title, $message); $b = mail(YAAMP_ADMIN_EMAIL, $title, $message);
if(!$b) debuglog('error sending email'); if(!$b) debuglog('error sending email');
memcache_set(controller()->memcache->memcache, "last_email_sent_$name", time()); controller()->memcache->set("last_email_sent_$name", time());
} }
function dos_filesize($fn) function dos_filesize($fn)

View file

@ -20,8 +20,7 @@ class ApiController extends CommonController
return; return;
} }
$memcache = controller()->memcache->memcache; $json = controller()->memcache->get("api_status");
$json = memcache_get($memcache, "api_status");
if (!empty($json)) { if (!empty($json)) {
echo $json; echo $json;
@ -97,7 +96,7 @@ class ApiController extends CommonController
$json = json_encode($stats); $json = json_encode($stats);
echo $json; echo $json;
memcache_set($memcache, "api_status", $json, MEMCACHE_COMPRESSED, 30); controller()->memcache->set("api_status", $json, MEMCACHE_COMPRESSED, 30);
} }
public function actionCurrencies() public function actionCurrencies()
@ -112,9 +111,7 @@ class ApiController extends CommonController
return; return;
} }
$memcache = controller()->memcache->memcache; $json = controller()->memcache->get("api_currencies");
$json = memcache_get($memcache, "api_currencies");
if (empty($json)) { if (empty($json)) {
$data = array(); $data = array();
@ -186,7 +183,7 @@ class ApiController extends CommonController
$data[$symbol]['symbol'] = $coin->symbol2; $data[$symbol]['symbol'] = $coin->symbol2;
} }
$json = json_encode($data); $json = json_encode($data);
memcache_set($memcache, "api_currencies", $json, MEMCACHE_COMPRESSED, 15); controller()->memcache->set("api_currencies", $json, MEMCACHE_COMPRESSED, 15);
} }
echo str_replace("},","},\n", $json); echo str_replace("},","},\n", $json);

View file

@ -415,7 +415,7 @@ class SiteController extends CommonController
$algo = user()->getState('yaamp-algo'); $algo = user()->getState('yaamp-algo');
$memcache = controller()->memcache->memcache; $memcache = controller()->memcache->memcache;
$memkey = $algo.'_'.str_replace('/','_',$partial); $memkey = $algo.'_'.str_replace('/','_',$partial);
$html = memcache_get($memcache, $memkey); $html = controller()->memcache->get($memkey);
if (!empty($html)) { if (!empty($html)) {
echo $html; echo $html;
@ -428,7 +428,7 @@ class SiteController extends CommonController
$html = ob_get_clean(); $html = ob_get_clean();
echo $html; echo $html;
memcache_set($memcache, $memkey, $html, MEMCACHE_COMPRESSED, $cachetime); controller()->memcache->set($memkey, $html, MEMCACHE_COMPRESSED, $cachetime);
} }
// Pool Status : public right panel with all algos and live stats // Pool Status : public right panel with all algos and live stats

View file

@ -507,8 +507,8 @@ function cronstate2text($state)
} }
} }
//$state_block = memcache_get($this->memcache->memcache, 'cronjob_block_state'); //$state_block = $this->memcache->get('cronjob_block_state');
$state_main = memcache_get($this->memcache->memcache, 'cronjob_main_state'); $state_main = $this->memcache->get('cronjob_main_state');
$btc = getdbosql('db_coins', "symbol='BTC'"); $btc = getdbosql('db_coins', "symbol='BTC'");
if (!$btc) $btc = json_decode('{"id": 6, "balance": 0}'); if (!$btc) $btc = json_decode('{"id": 6, "balance": 0}');
@ -517,24 +517,24 @@ for($i=0; $i<10; $i++)
{ {
// if($i != $state_block-1 && $state_block>0) // if($i != $state_block-1 && $state_block>0)
// { // {
// $state = memcache_get($this->memcache->memcache, "cronjob_block_state_$i"); // $state = $this->memcache->get("cronjob_block_state_$i");
// if($state) echo "block $i "; // if($state) echo "block $i ";
// } // }
if($i != $state_main-1 && $state_main>0) if($i != $state_main-1 && $state_main>0)
{ {
$state = memcache_get($this->memcache->memcache, "cronjob_main_state_$i"); $state = $this->memcache->get("cronjob_main_state_$i");
if($state) echo "main $i "; if($state) echo "main $i ";
} }
} }
echo '</span>'; echo '</span>';
$block_time = sectoa(time()-memcache_get($this->memcache->memcache, "cronjob_block_time_start")); $block_time = sectoa(time()-$this->memcache->get("cronjob_block_time_start"));
$loop2_time = sectoa(time()-memcache_get($this->memcache->memcache, "cronjob_loop2_time_start")); $loop2_time = sectoa(time()-$this->memcache->get("cronjob_loop2_time_start"));
$main_time2 = sectoa(time()-memcache_get($this->memcache->memcache, "cronjob_main_time_start")); $main_time2 = sectoa(time()-$this->memcache->get("cronjob_main_time_start"));
$main_time = sectoa(memcache_get($this->memcache->memcache, "cronjob_main_time")); $main_time = sectoa($this->memcache->get("cronjob_main_time"));
$main_text = cronstate2text($state_main); $main_text = cronstate2text($state_main);
echo "*** main ($main_time) $state_main $main_text ($main_time2), loop2 ($loop2_time), block ($block_time)<br>"; echo "*** main ($main_time) $state_main $main_text ($main_time2), loop2 ($loop2_time), block ($block_time)<br>";

View file

@ -2,8 +2,7 @@
echo "<a href='/site/memcached'>refresh</a><br>"; echo "<a href='/site/memcached'>refresh</a><br>";
$memcache = controller()->memcache->memcache; $a = controller()->memcache->memcache->get( 'url-map');
$a = memcache_get($this->memcache->memcache, 'url-map');
function printStats($stat) function printStats($stat)
{ {
@ -51,7 +50,7 @@ function cmp($a, $b)
if (!empty($a)) if (!empty($a))
foreach($a as $url=>$n) foreach($a as $url=>$n)
{ {
$d = memcache_get($this->memcache->memcache, "$url-time"); $d = $this->memcache->get("$url-time");
$avg = $d/$n; $avg = $d/$n;
$res[] = array($url, $n, $d, $avg); $res[] = array($url, $n, $d, $avg);

View file

@ -18,7 +18,7 @@ class CronjobController extends CommonController
$uptime = exec('uptime'); $uptime = exec('uptime');
$apache_locked = memcache_get($this->memcache->memcache, 'apache_locked'); $apache_locked = $this->memcache->get('apache_locked');
if($apache_locked) return; if($apache_locked) return;
$b = preg_match('/load average: (.*)$/', $uptime, $m); $b = preg_match('/load average: (.*)$/', $uptime, $m);
@ -52,7 +52,7 @@ class CronjobController extends CommonController
$this->monitorApache(); $this->monitorApache();
$last_complete = memcache_get($this->memcache->memcache, "cronjob_block_time_start"); $last_complete = $this->memcache->get("cronjob_block_time_start");
if($last_complete+(5*60) < time()) if($last_complete+(5*60) < time())
dborun("update jobs set active=false"); dborun("update jobs set active=false");
@ -62,7 +62,7 @@ class CronjobController extends CommonController
BackendProcessList(); BackendProcessList();
BackendBlocksUpdate(); BackendBlocksUpdate();
memcache_set($this->memcache->memcache, "cronjob_block_time_start", time()); $this->memcache->set("cronjob_block_time_start", time());
// debuglog(__METHOD__); // debuglog(__METHOD__);
} }
@ -82,21 +82,21 @@ class CronjobController extends CommonController
MonitorBTC(); MonitorBTC();
$last = memcache_get($this->memcache->memcache, 'last_renting_payout2'); $last = $this->memcache->get('last_renting_payout2');
if($last + 5*60 < time()) if($last + 5*60 < time())
{ {
memcache_set($this->memcache->memcache, 'last_renting_payout2', time()); $this->memcache->set('last_renting_payout2', time());
BackendRentingPayout(); BackendRentingPayout();
} }
$last = memcache_get($this->memcache->memcache, 'last_stats2'); $last = $this->memcache->get('last_stats2');
if($last + 5*60 < time()) if($last + 5*60 < time())
{ {
memcache_set($this->memcache->memcache, 'last_stats2', time()); $this->memcache->set('last_stats2', time());
BackendStatsUpdate2(); BackendStatsUpdate2();
} }
memcache_set($this->memcache->memcache, "cronjob_loop2_time_start", time()); $this->memcache->set("cronjob_loop2_time_start", time());
// debuglog(__METHOD__); // debuglog(__METHOD__);
} }
@ -107,11 +107,11 @@ class CronjobController extends CommonController
// BackendRunCoinActions(); // BackendRunCoinActions();
$state = memcache_get($this->memcache->memcache, 'cronjob_main_state'); $state = $this->memcache->get('cronjob_main_state');
if(!$state) $state = 0; if(!$state) $state = 0;
memcache_set($this->memcache->memcache, 'cronjob_main_state', $state+1); $this->memcache->set('cronjob_main_state', $state+1);
memcache_set($this->memcache->memcache, "cronjob_main_state_$state", 1); $this->memcache->set("cronjob_main_state_$state", 1);
switch($state) switch($state)
{ {
@ -177,20 +177,20 @@ class CronjobController extends CommonController
break; break;
default: default:
memcache_set($this->memcache->memcache, 'cronjob_main_state', 0); $this->memcache->set('cronjob_main_state', 0);
BackendQuickClean(); BackendQuickClean();
$t = memcache_get($this->memcache->memcache, "cronjob_main_start_time"); $t = $this->memcache->get("cronjob_main_start_time");
$n = time(); $n = time();
memcache_set($this->memcache->memcache, "cronjob_main_time", $n-$t); $this->memcache->set("cronjob_main_time", $n-$t);
memcache_set($this->memcache->memcache, "cronjob_main_start_time", $n); $this->memcache->set("cronjob_main_start_time", $n);
} }
debuglog(__METHOD__." $state"); debuglog(__METHOD__." $state");
memcache_set($this->memcache->memcache, "cronjob_main_state_$state", 0); $this->memcache->set("cronjob_main_state_$state", 0);
memcache_set($this->memcache->memcache, "cronjob_main_time_start", time()); $this->memcache->set("cronjob_main_time_start", time());
if(!YAAMP_PRODUCTION) return; if(!YAAMP_PRODUCTION) return;
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
@ -203,14 +203,14 @@ class CronjobController extends CommonController
$mining->last_payout = time(); $mining->last_payout = time();
$mining->save(); $mining->save();
memcache_set($this->memcache->memcache, 'apache_locked', true); $this->memcache->set('apache_locked', true);
if(YAAMP_USE_NGINX) if(YAAMP_USE_NGINX)
system("service nginx stop"); system("service nginx stop");
sleep(10); sleep(10);
BackendDoBackup(); BackendDoBackup();
memcache_set($this->memcache->memcache, 'apache_locked', false); $this->memcache->set('apache_locked', false);
BackendPayments(); BackendPayments();
BackendCleanDatabase(); BackendCleanDatabase();