amphp / ext-uv

Other
191 stars 28 forks source link

how to set a watcher on multiple path #95

Closed nivpenso closed 2 years ago

nivpenso commented 3 years ago

Hi,

I want to know whether it is possible to set a watcher on multiple paths like /home/ /tmp/

when I try to do something like that:

uv_fs_event_init($loop, "/home", function($rsc, $name, $event, $status) {
   echo "changed1";
}, 0);
uv_fs_event_init($loop, "/tmp", function($rsc, $name, $event, $status) {
   echo "changed2";
}, 0);

I get the following error:

PHP Fatal error: uv_fs_event_init(): uv_fs_event_start failed

this error is thrown on the second time I try to call uv_fs_event_init

nivpenso commented 3 years ago

so after few hours of playing around it seems that if I don't store the return value of uv_fs_event_init in a local variable the callback will never be fired. Solution Just have store the return value of the function uv_fs_event_init a local variable

$fsevent1 = uv_fs_event_init($loop, "/home", function($rsc, $name, $event, $status) {
   echo "changed1";
}, 0);
$fsevent2 = uv_fs_event_init($loop, "/tmp", function($rsc, $name, $event, $status) {
   echo "changed2";
}, 0);
kelunik commented 2 years ago

Seems like this has been solved. :wink: