Skip to content

Instantly share code, notes, and snippets.

@boxrick
Created September 4, 2018 22:10
Show Gist options
  • Save boxrick/7342e8b89f9a295da4c95eeeb9996c78 to your computer and use it in GitHub Desktop.
Save boxrick/7342e8b89f9a295da4c95eeeb9996c78 to your computer and use it in GitHub Desktop.
PHP Page compare
#!/usr/bin/php
<?php
# Define variables
$page_cache = 'page.cache';
$page_to_check = 'https://www.nvidia.co.uk/geforce/buy/';
# Check if argument is passed in
if (isset($argv[1])) {
$page_cache_override = true;
} else {
$page_cache_override = false;
}
# Cache page is argument is passed in
function cache_page($overwrite_cache, $page_to_check, $page_cache) {
if ($overwrite_cache) {
$homepage = file_get_contents($page_to_check);
file_put_contents($page_cache, $homepage);
echo "Cached page new page contents\n";
}
}
function check_page($page_to_check, $page_cache) {
# Get page and cache contents and load into variable
$homepage = file_get_contents($page_to_check);
$page_cache = file_get_contents($page_cache);
echo md5($homepage) . "\n";
echo md5($page_cache) . "\n";
if ($homepage == $page_cache) {
echo "Cached page is the same\n";
} else {
echo "Cached page differs\n";
file_put_contents('current_page', $homepage);
file_put_contents('current_cache', $page_cache);
}
}
cache_page($page_cache_override, $page_to_check, $page_cache);
check_page($page_to_check, $page_cache);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment