0

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) ?

nbonniot
  • 1,034
  • 16
  • 33

3 Answers3

0

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.

nbonniot
  • 1,034
  • 16
  • 33
0

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 :).

WyriHaximus
  • 1,000
  • 6
  • 8
  • Thanks for your comment. I've already spotted [phpi](https://github.com/calcinai/phpi) as a great piece of inspiration. Nonetheless, in order to fully understand, let's take the example given [here](https://github.com/tsufeki/react-filesystem-monitor) as a test : this monitor binding is not related to time value, but more a stream event. AFAIC, I would expect that will keep the loop in an endless mode. Am I wrong? I know the react paradigm is splippery to say the least ast beginning so I would like to rock solid on basics. Thanks ! – nbonniot Apr 02 '18 at 11:53
  • Furthermore, after installing `inotify-tool`, that is exactly what I got (endless loop) – nbonniot Apr 02 '18 at 11:54
  • The first thing I would do is add a error handling function like: https://gist.github.com/WyriHaximus/c6249b01f7feba3aaa1c605116f5d60f – WyriHaximus Apr 02 '18 at 14:59
0

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

calcinai
  • 2,567
  • 14
  • 25