phplinuxserverfile-watcherincron

Watching folder with incron seems to kill my server


I would like to run a php script on a folder whenever content in that folder changes (a file is edited, or overwritten, or added or deleted).

The php script gets a hash code for each file in the folder, and writes all the lines in a hash.txt file (appending a line like hashcode:filename for each file, e.g. 2dbb8badb0925833c8ea03ffc941e3a0:file1_blabla.utf8).

After adding my user to /etc/incron.allow, I have edited my icrontab -e in the server, and added the following line:

/var/www/mydir/tests/ IN_ALL_EVENTS php -f /var/www/mydir/tests/mk_hash_list.php

The result: some kind of killer loop that collapse my server with an ever growing log, which shows lines like:

Jun 24 19:24:30 myserver incrond[22010]: (manuel) CMD (php -f /var/www/mydir/tests/hash_list.php)
Jun 24 19:24:30 myserver incrond[22010]: cannot fork process: Resource temporarily unavailable

Any tips? Is icrontab good for what I'm trying to do? Thanks.


Solution

  • The file to which the script appended data was written in the watched folder, creating an endless loop. The solution was to create a subfolder containing only the files that the script should analyze and keep both the script and the written file with the result outside of that watched subfolder.