PHP - Email notification whenever a remote file changes

前端 未结 3 873
死守一世寂寞
死守一世寂寞 2020-12-22 10:06

I was wondering if there\'s a way to have a php script on my web server email me whenever a file from another web server changes.

For instance, there\'s this file t

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-22 10:47

    Use crontab to setup checking script to run once a minute and compare this file with your locally stored version (or use md5 checksums instead - it will differ if file changes).

    file_get_contents('http://url-to-file', 'checkfile.tmp');
    if (md5(file_get_contents('lastfile.tmp')) != md5(file_get_contents('checkfile.tmp')))
    {
        //copy checkfile to lastfile
        unlink('lastfile.tmp');
        copy('checkfile.tmp', 'lastfile.tmp'); 
        //send email or do something you want ;)
    }
    

提交回复
热议问题