How to detect when a page gets updated with PHP

php, scripting

Solution

Use file_get_contents() to get the page's content, create a MD5 hash from it, and compare it with the hash you already have. I suggest storing this hash in a simple file.

$contents = file_get_contents('http://site.com/page');
$hash     = file_get_contents('hash'); // the text file where the hash is stored
if ($hash == ($pageHash = md5($contents))) {
  // the content is the same
} else {
  // the page has been updated, do whatever you need to do
  // and store the new hash in the file
  $fp = fopen('hash', 'w');
  fwrite($fp, $pageHash);
  fclose($fp);
}

Don't forget setting allow_url_fopen to On.

Problem

I was wondering how to detect when a page gets updated with PHP. I've researched things on Google, but came across nothing. What I want to do is call a specific function when a page gets updated. I will be running a cron job in order to run the code. I want something like this: ``` if (page updated) { //functions } else { //functions } ``` If I can't do something like that then I want to at least know how to detect when a page gets updated with PHP. Please help!

Original source