diff options
author | Simon | 2011-04-12 13:19:15 +0200 |
---|---|---|
committer | Simon | 2011-04-12 13:19:15 +0200 |
commit | 24d8c8540a3cc22d53098e7acca5c4a068920691 (patch) | |
tree | 6ef31a8347fd420e6c78135c887c868af20dc85a /library/Pbs | |
parent | Fehler in GroupGroupsMapper gefixxt (diff) | |
download | pbs2-24d8c8540a3cc22d53098e7acca5c4a068920691.tar.gz pbs2-24d8c8540a3cc22d53098e7acca5c4a068920691.tar.xz pbs2-24d8c8540a3cc22d53098e7acca5c4a068920691.zip |
Caching bei GroupGraphs eingebaut
Diffstat (limited to 'library/Pbs')
-rw-r--r-- | library/Pbs/Graph.php | 33 |
1 files changed, 28 insertions, 5 deletions
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){ |