Posted in php functions
2647
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
38
This Month
215
This Year
443

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
Be Yourself, Back Yourself
Kristie Bennett, Survivor
Random CSS Property

flex

The flex CSS shorthand property sets how a flex item will grow or shrink to fit the space available in its flex container.
flex css reference