From 24d8c8540a3cc22d53098e7acca5c4a068920691 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 12 Apr 2011 13:19:15 +0200 Subject: Caching bei GroupGraphs eingebaut --- library/Pbs/Graph.php | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'library') diff --git a/library/Pbs/Graph.php b/library/Pbs/Graph.php index c924b59..78b88f8 100644 --- a/library/Pbs/Graph.php +++ b/library/Pbs/Graph.php @@ -26,11 +26,34 @@ class Pbs_Graph{ $this->graphstring .= '}'; $this->graphstring = str_replace(array("\t","\n"),"",$this->graphstring); $this->graphstring = str_replace('"','\"',$this->graphstring); - - $str = 'echo "'; - $str .= $this->graphstring; - $str .= '" | dot -Tpng '; - passthru($str, $result); + + $md5 = md5($this->graphstring); + $path = "../resources/groupgraphs/"; + @mkdir($path ,0777, true); + + // randomly delete cached files, old files are not needed + // so delete it sometimes + if(rand(0,20) == 1){ + $days = "14"; // delete all files older than this many days + $seconds = ($days*24*60*60); + + $files = scandir($path); + foreach ($files as $num => $fname){ + if (file_exists("{$path}{$fname}") && ((time() - filemtime("{$path}{$fname}")) > $seconds)) { + $mod_time = filemtime("{$path}{$fname}"); + unlink("{$path}{$fname}"); + } + } + } + + if(!file_exists($path.$md5.".png")){ + $str = 'echo "'; + $str .= $this->graphstring; + $str .= '" | dot -Tpng >'.$path.$md5.".png"; + exec($str); + } + + passthru("cat ".$path.$md5.".png", $result); return $result; } private function getGroupTitle($groupID){ -- cgit v1.2.3-55-g7522