I want to check if a remote file has changed before saving it to my server. First I've checked if the file exists before executing a comparison using md5_file between the remote file and the local file, but this is really slow. Is there a faster way to check this?
$channelName = htmlspecialchars($_GET['channel'], ENT_QUOTES);
$json_array = json_decode(file_get_contents('http://api.hitbox.tv/media/live/'.strtolower($channelName)), true);
$getImage = $json_array['livestream'][0]['channel']['user_logo_small'];
$imageURL = "http://edge.vie.hitbox.tv/$getImage";
$imagePath = str_replace("/static/img/channel/", "", $getImage);
$ImageExtension = substr( strrchr($imagePath, '.'), 1);
$imageOutput = "images/$channelName.".$ImageExtension;
if (file_exists($imageOutput)) {
if (md5_file($imageURL) != md5_file($imageOutput)) {
file_put_contents($imageOutput, file_get_contents($imageURL));
}
} else {
file_put_contents($imageOutput, file_get_contents($imageURL));
}
Maybe someone can help me out a bit or lead me into the right direction ^^
Kind regards, Kazuto