Posted in php functions
2644
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
35
This Month
212
This Year
440

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


Random CSS Property

radial-gradient()

The radial-gradient() CSS function creates an image consisting of a progressive transition between two or more colors that radiate from an origin. Its shape may be a circle or an ellipse. The function's result is an object of the <gradient> data type, which is a special kind of <image>.
radial-gradient() css reference