0

我想在将远程文件保存到我的服务器之前检查它是否已更改。首先,我在使用远程文件和本地文件之间的 md5_file 执行比较之前检查了文件是否存在,但这确实很慢。有没有更快的方法来检查这个?

$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));
}

也许有人可以帮助我或引导我走向正确的方向^^

亲切的问候,和人

4

1 回答 1

0

我已经使用 Pack 和 Unpack 功能来做类似的事情。正在将图像和 pdf 文件转换为二进制而不是 md5。我不确定与 MD5 相比的性能,但可以看看它。

http://php.net/manual/en/function.pack.php

http://php.net/manual/en/function.unpack.php

于 2015-04-04T10:27:13.827 回答