Ok, I'm in need of a dir monitor that continually scans a dir for new .txt files added. Opens the .txt file, reads/parses the content and writes data to a mysql table. I'm looking into inotify which seems like it is robust and can accomplish this task, but I don't quiet understand how the command sequence would look to accomplish what I mentioned above.
Here is a potential example (tell me if I'm thinking through this properly):
$fd = inotify_init();
$watch_descriptor = inotify_add_watch($fd, '/some/system/dir/', IN_CREATE);
// Loop forever (never break out of loop since I want to ALWAYS monitor this dir)
while (true) {
$events = inotify_read($fd);
//THIS IS WHERE I DON'T KNOW HOW TO OPEN THE NEWLY CREATED FILE
//PLEASE HELP HERE WITH HOW TO SUCCESSFULLY CREATE THE EVENT ACTIONS
/*
1) OPEN FILE
2) READ/PARSE CONTENTS
3) CREATE MYSQL INSERT STATEMENT
4) DELETE FILE
*/
}
One question this brings up is: Will continuing this loop forever consume a ridiculous amount of processor capacity? and: If so, is this truly the method I should use to accomplish my goal?
Any help understanding inotify and the sequence required to accomplish my goal would be very helpful.
Thank you in advance.