Skip to content

Commit

Permalink
use memcache object method instead of low level method (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutangar authored and tpruvot committed Mar 6, 2018
1 parent 8c85b95 commit 1e06755
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 41 deletions.
4 changes: 2 additions & 2 deletions web/yaamp/core/common/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ function send_email_alert($name, $title, $message, $t=10)
{
// 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;

debuglog("mail('".YAAMP_ADMIN_EMAIL."', $title, ...)");

$b = mail(YAAMP_ADMIN_EMAIL, $title, $message);
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)
Expand Down
11 changes: 4 additions & 7 deletions web/yaamp/modules/api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public function actionStatus()
return;
}

$memcache = controller()->memcache->memcache;
$json = memcache_get($memcache, "api_status");
$json = controller()->memcache->get("api_status");

if (!empty($json)) {
echo $json;
Expand Down Expand Up @@ -97,7 +96,7 @@ public function actionStatus()
$json = json_encode($stats);
echo $json;

memcache_set($memcache, "api_status", $json, MEMCACHE_COMPRESSED, 30);
controller()->memcache->set("api_status", $json, MEMCACHE_COMPRESSED, 30);
}

public function actionCurrencies()
Expand All @@ -112,9 +111,7 @@ public function actionCurrencies()
return;
}

$memcache = controller()->memcache->memcache;

$json = memcache_get($memcache, "api_currencies");
$json = controller()->memcache->get("api_currencies");
if (empty($json)) {

$data = array();
Expand Down Expand Up @@ -186,7 +183,7 @@ public function actionCurrencies()
$data[$symbol]['symbol'] = $coin->symbol2;
}
$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);
Expand Down
4 changes: 2 additions & 2 deletions web/yaamp/modules/site/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ protected function renderPartialAlgoMemcached($partial, $cachetime=15)
$algo = user()->getState('yaamp-algo');
$memcache = controller()->memcache->memcache;
$memkey = $algo.'_'.str_replace('/','_',$partial);
$html = memcache_get($memcache, $memkey);
$html = controller()->memcache->get($memkey);

if (!empty($html)) {
echo $html;
Expand All @@ -428,7 +428,7 @@ protected function renderPartialAlgoMemcached($partial, $cachetime=15)
$html = ob_get_clean();
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
Expand Down
16 changes: 8 additions & 8 deletions web/yaamp/modules/site/common_results.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ function cronstate2text($state)
}
}

//$state_block = memcache_get($this->memcache->memcache, 'cronjob_block_state');
$state_main = memcache_get($this->memcache->memcache, 'cronjob_main_state');
//$state_block = $this->memcache->get('cronjob_block_state');
$state_main = $this->memcache->get('cronjob_main_state');
$btc = getdbosql('db_coins', "symbol='BTC'");
if (!$btc) $btc = json_decode('{"id": 6, "balance": 0}');

Expand All @@ -517,24 +517,24 @@ function cronstate2text($state)
{
// 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($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 ";
}
}

echo '</span>';

$block_time = sectoa(time()-memcache_get($this->memcache->memcache, "cronjob_block_time_start"));
$loop2_time = sectoa(time()-memcache_get($this->memcache->memcache, "cronjob_loop2_time_start"));
$main_time2 = sectoa(time()-memcache_get($this->memcache->memcache, "cronjob_main_time_start"));
$block_time = sectoa(time()-$this->memcache->get("cronjob_block_time_start"));
$loop2_time = sectoa(time()-$this->memcache->get("cronjob_loop2_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);

echo "*** main ($main_time) $state_main $main_text ($main_time2), loop2 ($loop2_time), block ($block_time)<br>";
Expand Down
5 changes: 2 additions & 3 deletions web/yaamp/modules/site/memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

echo "<a href='/site/memcached'>refresh</a><br>";

$memcache = controller()->memcache->memcache;
$a = memcache_get($this->memcache->memcache, 'url-map');
$a = controller()->memcache->memcache->get( 'url-map');

function printStats($stat)
{
Expand Down Expand Up @@ -51,7 +50,7 @@ function cmp($a, $b)
if (!empty($a))
foreach($a as $url=>$n)
{
$d = memcache_get($this->memcache->memcache, "$url-time");
$d = $this->memcache->get("$url-time");
$avg = $d/$n;

$res[] = array($url, $n, $d, $avg);
Expand Down
38 changes: 19 additions & 19 deletions web/yaamp/modules/thread/CronjobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private function monitorApache()

$uptime = exec('uptime');

$apache_locked = memcache_get($this->memcache->memcache, 'apache_locked');
$apache_locked = $this->memcache->get('apache_locked');
if($apache_locked) return;

$b = preg_match('/load average: (.*)$/', $uptime, $m);
Expand Down Expand Up @@ -52,7 +52,7 @@ public function actionRunBlocks()

$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())
dborun("update jobs set active=false");

Expand All @@ -62,7 +62,7 @@ public function actionRunBlocks()
BackendProcessList();
BackendBlocksUpdate();

memcache_set($this->memcache->memcache, "cronjob_block_time_start", time());
$this->memcache->set("cronjob_block_time_start", time());
// debuglog(__METHOD__);
}

Expand All @@ -82,21 +82,21 @@ public function actionRunLoop2()

MonitorBTC();

$last = memcache_get($this->memcache->memcache, 'last_renting_payout2');
$last = $this->memcache->get('last_renting_payout2');
if($last + 5*60 < time())
{
memcache_set($this->memcache->memcache, 'last_renting_payout2', time());
$this->memcache->set('last_renting_payout2', time());
BackendRentingPayout();
}

$last = memcache_get($this->memcache->memcache, 'last_stats2');
$last = $this->memcache->get('last_stats2');
if($last + 5*60 < time())
{
memcache_set($this->memcache->memcache, 'last_stats2', time());
$this->memcache->set('last_stats2', time());
BackendStatsUpdate2();
}

memcache_set($this->memcache->memcache, "cronjob_loop2_time_start", time());
$this->memcache->set("cronjob_loop2_time_start", time());
// debuglog(__METHOD__);
}

Expand All @@ -107,11 +107,11 @@ public function actionRun()

// BackendRunCoinActions();

$state = memcache_get($this->memcache->memcache, 'cronjob_main_state');
$state = $this->memcache->get('cronjob_main_state');
if(!$state) $state = 0;

memcache_set($this->memcache->memcache, 'cronjob_main_state', $state+1);
memcache_set($this->memcache->memcache, "cronjob_main_state_$state", 1);
$this->memcache->set('cronjob_main_state', $state+1);
$this->memcache->set("cronjob_main_state_$state", 1);

switch($state)
{
Expand Down Expand Up @@ -177,20 +177,20 @@ public function actionRun()
break;

default:
memcache_set($this->memcache->memcache, 'cronjob_main_state', 0);
$this->memcache->set('cronjob_main_state', 0);
BackendQuickClean();

$t = memcache_get($this->memcache->memcache, "cronjob_main_start_time");
$t = $this->memcache->get("cronjob_main_start_time");
$n = time();

memcache_set($this->memcache->memcache, "cronjob_main_time", $n-$t);
memcache_set($this->memcache->memcache, "cronjob_main_start_time", $n);
$this->memcache->set("cronjob_main_time", $n-$t);
$this->memcache->set("cronjob_main_start_time", $n);
}

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;

///////////////////////////////////////////////////////////////////
Expand All @@ -203,14 +203,14 @@ public function actionRun()
$mining->last_payout = time();
$mining->save();

memcache_set($this->memcache->memcache, 'apache_locked', true);
$this->memcache->set('apache_locked', true);
if(YAAMP_USE_NGINX)
system("service nginx stop");

sleep(10);
BackendDoBackup();

memcache_set($this->memcache->memcache, 'apache_locked', false);
$this->memcache->set('apache_locked', false);

BackendPayments();
BackendCleanDatabase();
Expand Down

0 comments on commit 1e06755

Please sign in to comment.