Posted in php functions
2657
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
27
This Month
86
This Year
453

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
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better. You won't believe what you can accomplish by attempting the impossible with the courage to repeatedly fail better.
Unknown
Random CSS Property

math-style

The math-style property indicates whether MathML equations should render with normal or compact height.
math-style css reference