summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorSimon2011-04-12 13:19:15 +0200
committerSimon2011-04-12 13:19:15 +0200
commit24d8c8540a3cc22d53098e7acca5c4a068920691 (patch)
tree6ef31a8347fd420e6c78135c887c868af20dc85a /library
parentFehler in GroupGroupsMapper gefixxt (diff)
downloadpbs2-24d8c8540a3cc22d53098e7acca5c4a068920691.tar.gz
pbs2-24d8c8540a3cc22d53098e7acca5c4a068920691.tar.xz
pbs2-24d8c8540a3cc22d53098e7acca5c4a068920691.zip
Caching bei GroupGraphs eingebaut
Diffstat (limited to 'library')
-rw-r--r--library/Pbs/Graph.php33
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){