How to check if a file is the same file as before

I need to check if the file that existed in the directory on the server, the same file that was there 5 minutes ago?

In a specific directory, I delete and recreate a file with the same name every few minutes. A script is accessing a file every 2 minutes. So, at time t, the script checks the file and does the stuff. Then, at time t + 1, the file is deleted and recreated (with the same name, but possibly with different content). Then at time t + 2, the script again searches for the file.

So, in the second check, is there a way to check if the file has been modified or not (without reading the contents)?

+3
source share
8 answers

, , , , - , filemtime().

, , .


, ( , ) - : , .
PHP filesize().


, , , md5 sha1 .

PHP , , :

+10

" " , md5_file(), , .

.

<?php

$file1_fp = md5_file($fname1);
$file2_fp = md5_file($fname2);

if ($file1_fp === $file2_fp )
{

  //do something..
}

?>

. http://php.net/manual/en/function.md5-file.php

+4

PHP filemtime, .

!

, script , ! , clearstatcache filemtime.

filemtime script ( script), , clearstatcache.

+3

timestamp, , , MD5 digest .. -.

0

, . MD5:

md5(file_get_contents('/path/to/file'))

( OS FS ) .

0

fileinode(). , inode , .

0

MD5 -

0

All Articles