Skip to content

events called perpetually #2

Description

@basz

using the notify backend i've noticed an event handler keeps getting called. Should I do something in the handler?

calling stopPropagation on the event prevents the handler being called multiple times, but the logger still shows the create/deletion multiple times.

<?php

/**
 * change this to point to the lumasol data directory
 */
$lumasolRootDataPath = __DIR__ . '/../data';

error_reporting(E_ALL);
ini_set('display_errors', 'on');

require_once __DIR__ . '/../vendor/autoload.php';

$lumasolRootDataPath = realpath($lumasolRootDataPath);

if ($lumasolRootDataPath === false) {
    die("lumasol data path incorrect");
}

use Monolog\Logger;
use Monolog\Handler\StreamHandler;


$watcher = \Kwf\FileWatcher\Watcher::create($lumasolRootDataPath);

// logging to console
$logger = new Logger('filewatcher');
$logger->pushHandler(new StreamHandler(fopen('php://stdout', 'w'), Logger::DEBUG));
$watcher->setLogger($logger);

$watcher->addListener(\Kwf\FileWatcher\Event\Create::NAME, function (\Symfony\Component\EventDispatcher\Event $e) {
    var_dump($e);
    $e->stopPropagation();
});
$watcher->addListener(\Kwf\FileWatcher\Event\Delete::NAME, function (\Symfony\Component\EventDispatcher\Event $e) {
    var_dump($e);
    $e->stopPropagation();
});

$watcher->start();

output while creating a file and then deleting it...

[lumasol@srv1 public_html]$ ./bin/emailer.sh 
[2017-08-03 15:48:58] filewatcher.INFO: Watches set up... [] []
[2017-08-03 15:49:04] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
object(Kwf\FileWatcher\Event\Create)#7 (4) {
  ["filename"]=>
  string(40) "/home/lumasol/lumasol-data/untitled file"
  ["propagationStopped":"Symfony\Component\EventDispatcher\Event":private]=>
  bool(false)
  ["dispatcher":"Symfony\Component\EventDispatcher\Event":private]=>
  object(Symfony\Component\EventDispatcher\EventDispatcher)#13 (2) {
    ["listeners":"Symfony\Component\EventDispatcher\EventDispatcher":private]=>
    array(2) {
      ["filewatcher.create"]=>
      array(1) {
        [0]=>
        array(1) {
          [0]=>
          object(Closure)#12 (1) {
            ["parameter"]=>
            array(1) {
              ["$e"]=>
              string(10) "<required>"
            }
          }
        }
      }
      ["filewatcher.delete"]=>
      array(1) {
        [0]=>
        array(1) {
          [0]=>
          object(Closure)#16 (1) {
            ["parameter"]=>
            array(1) {
              ["$e"]=>
              string(10) "<required>"
            }
          }
        }
      }
    }
    ["sorted":"Symfony\Component\EventDispatcher\EventDispatcher":private]=>
    array(1) {
      ["filewatcher.create"]=>
      array(1) {
        [0]=>
        object(Closure)#12 (1) {
          ["parameter"]=>
          array(1) {
            ["$e"]=>
            string(10) "<required>"
          }
        }
      }
    }
  }
  ["name":"Symfony\Component\EventDispatcher\Event":private]=>
  string(18) "filewatcher.create"
}
[2017-08-03 15:49:04] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:04] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:04] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:04] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:04] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:04] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:04] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:05] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:05] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:05] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:05] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:05] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:05] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:05] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:05] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:05] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:05] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:06] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:06] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:06] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:06] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:06] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:06] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:06] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:06] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:06] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:06] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
object(Kwf\FileWatcher\Event\Delete)#5 (4) {
  ["filename"]=>
  string(40) "/home/lumasol/lumasol-data/untitled file"
  ["propagationStopped":"Symfony\Component\EventDispatcher\Event":private]=>
  bool(false)
  ["dispatcher":"Symfony\Component\EventDispatcher\Event":private]=>
  object(Symfony\Component\EventDispatcher\EventDispatcher)#13 (2) {
    ["listeners":"Symfony\Component\EventDispatcher\EventDispatcher":private]=>
    array(2) {
      ["filewatcher.create"]=>
      array(1) {
        [0]=>
        array(1) {
          [0]=>
          object(Closure)#12 (1) {
            ["parameter"]=>
            array(1) {
              ["$e"]=>
              string(10) "<required>"
            }
          }
        }
      }
      ["filewatcher.delete"]=>
      array(1) {
        [0]=>
        array(1) {
          [0]=>
          object(Closure)#16 (1) {
            ["parameter"]=>
            array(1) {
              ["$e"]=>
              string(10) "<required>"
            }
          }
        }
      }
    }
    ["sorted":"Symfony\Component\EventDispatcher\EventDispatcher":private]=>
    array(2) {
      ["filewatcher.create"]=>
      array(1) {
        [0]=>
        object(Closure)#12 (1) {
          ["parameter"]=>
          array(1) {
            ["$e"]=>
            string(10) "<required>"
          }
        }
      }
      ["filewatcher.delete"]=>
      array(1) {
        [0]=>
        object(Closure)#16 (1) {
          ["parameter"]=>
          array(1) {
            ["$e"]=>
            string(10) "<required>"
          }
        }
      }
    }
  }
  ["name":"Symfony\Component\EventDispatcher\Event":private]=>
  string(18) "filewatcher.delete"
}
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:07] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:08] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.create: /home/lumasol/lumasol-data/untitled file [] []
[2017-08-03 15:49:09] filewatcher.INFO: filewatcher.delete: /home/lumasol/lumasol-data/untitled file [] []

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions