Calculate the MD5 checksum of a file over and over, clearing the disk cache between each read, to try to identify read errors that are happening on a hard drive. Ref: https://www.pommepause.com/2016/02/the-case-of-the-dying-hard-drive-that-flipped-bits/
<?php | |
$file = '/mnt/hdd5/persistent-app-data/downloading/vvgoor1586DSFGKL.part10.rar'; | |
while (TRUE) { | |
exec("sync ; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'"); | |
$data1 = file_get_contents($file); | |
exec("sync ; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'"); | |
$data2 = file_get_contents($file); | |
$md5_data1 = md5($data1); | |
$md5_data2 = md5($data2); | |
if ($md5_data1 != $md5_data2) { | |
echo "First read MD5: $md5_data1\n"; | |
echo "Second read MD5: $md5_data2\n"; | |
for ($i=0; $i<strlen($data1); $i++) { | |
if ($data1[$i] != $data2[$i]) { | |
echo "Wrong byte at pos $i: 0x" . dechex(ord($data1[$i])) . " vs 0x" . dechex(ord($data2[$i])) . "\n"; | |
} | |
} | |
} else { | |
echo "OK\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment