Posted in php functions
2648
6:45 am, September 19, 2022
 

simple file cache and check in php

just a quick cache bit of code, may need tweaking to actually work... i just added it here as i thought it was re-usable. 

Also requires simple_html_dom library.

PHP

/* file cache */
      require_once("lib/simple_html_dom.php");
      $import_url_md5 = md5($import_url);
      $current_working_directory = getcwd();
      $filename = $current_working_directory . "/cache/" . $import_url_md5 . ".html";
      $filename_link = "/cache/" . $import_url_md5 . ".html";

      // cache it... or not...
      $file_cache = true;
      if($file_cache) {
        if(file_exists($filename)) {
          $out .= "using cache file: <a href='$filename_link'>$filename_link</a> <br />";
          $html = file_get_html($filename);
        } else {
          $out .= "added cache file: <a href='$filename_link'>$filename_link</a> <br />";
          $html = file_get_html($import_url);
          // save it for later...
          file_put_contents(
             $filename,
             $html
          );
        }
      } else {
        // no cache
        $out .= "cache disabled<br />";
        $html = file_get_html($import_url);
      }
      // return $out;
      // exit();
      /* file cache */

View Statistics
This Week
39
This Month
216
This Year
444

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote


Me
Random CSS Property

:any-link

The :any-link CSS pseudo-class selector represents an element that acts as the source anchor of a hyperlink, independent of whether it has been visited. In other words, it matches every <a> or <area> element that has an href attribute. Thus, it matches all elements that match :link or :visited.
:any-link css reference