public static function downloadRecipeWithCache($url) { $cache_ttl = 86400 * 3; // Target filename $filename = FileUtil::tempFilenameFromUrl($url); // Only fetch 1x per day if (file_exists($filename) && filesize($filename) > 0 && time() - filemtime($filename) < $cache_ttl) { error_log("Found file in cache: {$filename}"); $html = file_get_contents($filename); } else { // Fetch and cleanup the HTML error_log("Downloading recipe from url: {$url}"); $html = FileUtil::downloadPage($url); $html = RecipeParser_Text::forceUTF8($html); $html = RecipeParser_Text::cleanupClippedRecipeHtml($html); // Append some notes to the HTML $comments = RecipeParser_Text::getRecipeMetadataComment($url, "curl"); $html = $comments . "\n\n" . $html; error_log("Saving recipe to file {$filename}"); file_put_contents($filename, $html); } return $html; }