I use inotifywait to watch a folder for new files, and send the path of the file to a php script to process it when "close_write" is detected.
The command looks like this:
inotifywait -e close_write --format '%w%f' -m -r /path/do/dir | while read LINE; do php /home/scripts/watcher.php $LINE; done
When its executed in ssh, it works perfectly. When I wrap it in a exec() or system() functions in php, in order to run it as a daemon with supervisor, it doesn't pass the 2nd arg to the watcher.php script that usually contains the absolute path of the file that triggered inotifywait.
exec() doesn't even trigger the script at all, while passthru() and system() actually hit watcher.php but with no args other than the first one, which contains the path of the script itself.
When the wrapper script is executed, to bein watching the folder, it gives the output from ionotifywait:
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
When a new file is uploaded, nothing happens. watcher.php is not triggered.
When I use passthru() or system() and upload a file, it hits watcher.php, which does this at the top of the file: print_r($argv);
passthru("inotifywait -e close_write --format '%w%f' -m -r /path/do/dir | while read LINE; do php /home/scripts/watcher.php $LINE; done");
This only outputs
Array (
[0] => /home/scripts/watcher.php
)
If I run ionotifywait command in cli manually, it prints the expected output when a new file is uploaded
Array
(
[0] => /home/scripts/watcher.php
[1] => /path/to/dir/hello.jpg
)