PHP - Email notification whenever a remote file changes

前端 未结 3 862
死守一世寂寞
死守一世寂寞 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:59

    You need have this two files in same folder.

    • old.json
    • scriptForCron.php

    In scriptForCron.php write:

    $url='http://media1.clubpenguin.com/play/en/web_service/game_configs/paper_items.json';
    $ch = curl_init($url);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $execute = curl_exec($ch);
    
    $fp=fopen('old.json','w+');
    $oldjson=fread($fp,filesize('old.json'));
    
    if($execute!=$oldjson){
     mail('your@mail.com','Yoohoo', 'File changed');
     fputs($fp,$execute);
    }
    fclose($fp);
    

    And then add scriptForCron.php to cron job. You can ask hosting support for it.

提交回复
热议问题