noalyss Version-9
Static Public Member Functions
Noalyss\File_Cache Class Reference
+ Collaboration diagram for Noalyss\File_Cache:

Static Public Member Functions

static get_content ($url, $filename, $time_cache_second)
 Check if the file exists, if yes then read otherwise take it from the url,. More...
 

Detailed Description

Definition at line 35 of file file_cache.class.php.

Member Function Documentation

◆ get_content()

static Noalyss\File_Cache::get_content (   $url,
  $filename,
  $time_cache_second 
)
static

Check if the file exists, if yes then read otherwise take it from the url,.

Parameters
$urlurl to the file to get the content
$filenamefullpath to the filename of the cache
$time_cache_secondvalid time, if the cache is older , than reload it from the url
Returns
void

Definition at line 44 of file file_cache.class.php.

45 {
46 $content = null;
47 if (file_exists($filename)) {
48 $date_time = new \DateTime();
49 $file_tmstamp = filemtime($filename);
50
51 $delta = $date_time->getTimestamp() - $file_tmstamp;
52
53 // if file too old , refresh it
54 if ($delta > $time_cache_second) {
55 $content = file_get_contents($url);
56 $f_file = fopen($filename, "w+");
57 if ( $f_file == false ) {
58 return $content;
59 }
60 fwrite($f_file, $content);
61 fclose($f_file);
62 } else {
63 $content = file_get_contents($filename);
64 }
65 } else {
66 $content = @file_get_contents($url);
67 $f_file = fopen($filename, "w+");
68 if ( $f_file == false ) {
69 return $content;
70 }
71 fwrite($f_file, $content);
72 fclose($f_file);
73
74 }
75 return $content;
76 }
$url
$content
Definition: xml.php:17

References $content, $delta, and $url.


The documentation for this class was generated from the following file: