From: Robert Kaiser Date: Mon, 27 Jun 2016 16:48:48 +0000 (+0200) Subject: only cache the last_update value for 10 seconds, so that we can reasonably use this... X-Git-Url: https://git-public.kairo.at/?p=php-utility-classes.git;a=commitdiff_plain;h=7edd708f85562943539ec927775c1b083f079b2d;hp=c797f39a6abd6294e222b01d9be5d53ef442462a only cache the last_update value for 10 seconds, so that we can reasonably use this function to wait for updates but still don't flodd the commandline with requests --- diff --git a/include/classes/rrdstat.php-class b/include/classes/rrdstat.php-class index aa7079d..ce334e0 100644 --- a/include/classes/rrdstat.php-class +++ b/include/classes/rrdstat.php-class @@ -476,11 +476,13 @@ class rrdstat { public function last_update() { // fetch time of last update in this RRD file - static $last_update; + static $last_update, $last_saved; + if (isset($last_update) && isset($last_saved) && ($last_saved <= (time() - 10))) { unset($last_update); } if (!isset($last_update) && in_array($this->status, array('ok','readonly'))) { $last_cmd = $this->rrdtool_bin.' last '.$this->rrd_file; $return = trim(`$last_cmd 2>&1`); $last_update = is_numeric($return)?$return:null; + $last_saved = time(); } return isset($last_update)?$last_update:null; }