Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Monitor File Changes on Server - MD5 or ?

Status
Not open for further replies.

Geronantimo

Technical User
Apr 3, 2006
79
SE
After the deployment of a website, I would like to periodically run a script to monitor specified directories and sub-directories for file changes. (I might also like to specify the file types by extension.)

My query is, can this be accomplished with PHP and if so, where should I start looking?

I have seen a very short post elsewhere that referred to using the MD5 checksum as a way of saving information about all of the files and then running a comparision after a period of time.

It might be sufficient to simply display file changes according to the datestamp.

The reason why I would like to be able to do this is that when an "upgrade" is available for an application, often it requires uploading many files to the server. I would like to know which files have changed since the previous upload so I can locate files that have been edited and not overwrite them before comparing their contents.

Might the best solution involve using a database to store the information about individual files?

Apart from the usefulness prior to an upgrade, this script would also be a useful security measure.

If any of this is possible, perhaps someone could start me off on the right track.

Thanks.
 
taking the checksums of files is one way of doing it. timestamps are another, if you can be sure that none of your apps play silly buggers with timestamps (for example i have found that chronosync reset all of my timestamps once during a sync exercise - absolute disaster)

neither of these are particularly granular methods. better still might be to use diff. then you can actually see what has been changed.

best of all is to design your app so that you never deploy user editable files in the installation package. this way your package never overwrites the active version. For example you would not deploy a php.ini file, but instead a php.ini.recommended etc.

alternatively, you could have all user edited files stored in a particular directory. then in the packaged counterparts you could use code like so

Code:
if (file_exists('useredits/'__FILE__)){
 include 'useredits/'__FILE__;
} else {
 //normal file

}
so that the user edits are 'hooked' into the app space in place of your vanilla files. so called 'pluggable' scripts.
 
Hi JPadie,

Thanks for the quick response.
best of all is to design your app so that you never deploy user editable files in the installation package. this way your package never overwrites the active version
That's a good idea but the files that are edited are mostly PHP files that I have edited myself.

Might not another solution be this - I always make a small comment in the files that I have edited, such as
Code:
//Geronantimo
If I am looking for the files that contain this comment, perhaps I could use grep to search within files in a particular directory and sub-directories.

Is this a practical alternative?
 
if you can guarantee always doing so, then yes. i would couple it with timestamp analysis too though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top