NICON Posted November 22, 2016 Share Posted November 22, 2016 (edited) function callback($buffer) { global $user_class, $db, $m; if (!$m->get('membersonline.' . $user_class->gang)) { $db->query("SELECT COUNT(id) FROM grpgusers WHERE gang = ? AND lastactive >= ?"); $db->execute(array( $user_class->gang, time() - 900 )); $membersonline = $db->fetch_single(); $m->set('membersonline.' . $user_class->gang, $membersonline); } else $membersonline = $m->get('membersonline.' . $user_class->gang); $buffer = str_replace("<!_-monline-_!>", $membersonline ? "<font color='yellow'><strong>" . prettynum($membersonline) . "</strong></font>" : 0, $buffer); return $buffer; } ob_start("callback"); <a href="test.php">Test Line [<!_-monline-_!>]</a> My problem is quite simple but yet I cant figure it out. I want $membersonline to update as people go inactive using the existing format for similar data. Above is just that but as the number increases it just holds to the highest number and never drops lower. i.e. if the value shown is 3 and I check who is online and its 1 why is 3 still showing? Thanks in advance. Edited November 22, 2016 by NICON Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted November 23, 2016 Solution Share Posted November 23, 2016 What's $m->get/set? Caching? Is that working correctly? It doesn't look like the ->get is setting any sort of TTL or expiration time... Quote Link to comment Share on other sites More sharing options...
NICON Posted November 29, 2016 Author Share Posted November 29, 2016 That was the issue. I had stored a permanent variable in the cache and of coarse it would not update. I fixed it though with this: if (!$m->get('membersonline.' . $user_class->gang)) { $db->query("SELECT COUNT(id) FROM grpgusers WHERE gang = ? AND lastactive >= ?"); $db->execute(array( $user_class->gang, time() - 900 )); $membersonline = $db->fetch_single(); $m->set('membersonline.' . $user_class->gang, $membersonline, 1); } else $membersonline = $m->get('membersonline.' . $user_class->gang); of coarse I enabled this after destroying the old variable. Thanks for your reply! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.