I would like to use this for monitoring sysfs GPIO input (/sys/class/gpio
).
But when I test the given code as example, the scripts finishes (no error) just after the $loop->run()
.
How can I make this loop permanent (endless one) ?
My problem came from inotifywait
wasn't on my system.
One apt-get install inotify-tools
solved it.
Now my script is in an infinite loop as expected.
Hey ReactPHP core team member here. The event loop only keeps running when it has something to do such as handling streams, timers, or ticks. So if there is an error somewhere you don't catch or respond to the loop will end as the only thing doing something stopped because of an error. Also I've heard good things about https://github.com/calcinai/phpi might be of interest for you :).
I'm not completely sure if this is still the case, but I recall that those sysfs
files were actually "deleted" and "recreated" on change (as opposed to edited), so using any inode type monitoring is likely to fail.
You may be able to watch the directory instead; from what I understand it uses a different approach to detect changes