How can I monitor file changes in folders using php?

Source: Internet
Author: User
1. on stackoverflow, someone said that using md5 to implement the link stackoverflow. comques .... Please let me know how to achieve this. 3Q2, is there any other way to achieve monitoring? 1. on stack overflow, someone says that the link to md5 is http://stackoverflow.com/ques .... Please let me know how to implement it, 3Q
2. is there any other way to achieve monitoring?

Reply content:

1. on stack overflow, someone says that the link to md5 is http://stackoverflow.com/ques .... Please let me know how to implement it, 3Q
2. is there any other way to achieve monitoring?

1. Passscandir()Obtain all the files in this directory;
2.foreachTo traverse a file, usemd5file()Save the file's md5 value to a file in another directory OR database (why is it not an array OR another variable? Because the variables are cleared every time they are executed );
3. run the cron or windows scheduled task, convert the md5 list to an array, and then usearray_diff()Compare the md5 list with the currentscandir()The list of obtained md5 files. if any result is returned, the files are modified, deleted, or added.

You can try the mtime and ctime of the Directory.

The Linux kernel has an event-driven Inotify mechanism (C document) that supports listening for directory and file changes.
PHP also has such a PECL extension bound to this Inotify operation.
Http://pecl.php.net/package/ I...
Http://cn.php.net/manual/zh/ B...
Or you can use PHP to call the command tool provided by inotify-tools.

According to the above two brothers, inofiy is used for real-time purposes. if you need to determine the file differences similar to those when submitting code, you can use the md5 value and other file fingerprints.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.