Posted in php functions
2681
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
21
This Month
110
This Year
477

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
There is no way to happiness. Happiness is the way.
Unknown
Random CSS Property

inset-inline-end

The inset-inline-end CSS property defines the logical inline end inset of an element, which maps to a physical offset depending on the element's writing mode, directionality, and text orientation. It corresponds to the top, right, bottom, or left property depending on the values defined for writing-mode, direction, and text-orientation.
inset-inline-end css reference