Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Johannes Kiehl
December 21, 2006, 1:47 pm
rate this thread
I want a PHP script to "wake up" as soon as a file in a directory has been
modified (by some other script). The obvious solution that comes to mind
would be a ( readdir, filectime, maybe sleep ) loop, but I am concerned
about CPU and filesystem load.
thanks to y'all,
Please don't send personal email to the From: address. -->>
ed tod iduej ta oj :siht rof bmud oot era stobmaps epoH <<--
Re: monitor file (inode) changes effectively, how?
I did something like this once. Keep in mind, though, that this was
only a small piece of a much larger school project and thus, not
perfectly designed and may not have scaled effeciently in the end. It
was also designed for *BSD. It assumes you have complete control of
your server and aren't on a shared environment (shared hosts may not
let you do it).
I wrote a system daemon in C that attached itself to the FAM (File
Alteration Monitor, i think it stands for). You can register with FAM
to have it tell you when something happens to individual files, or a
whole directory structure. The daemon would just run in the background
and when FAM detected a change, the daemon would log the file and what
happened. I then had a php script run periodically via cron that
parsed the log and performed whatever actions needed to occur. If time
is critical, then you could easily modify this scenario to have the
daemon call the php script directly instead of waiting.
This worked very well for our limited needs, but if I were going to
reimplement the same thing in a production environment, I would
extensively test the heck out of it.