/**
  * Poll stdin for Supervisord notifications and dispatch notifications to
  * the callback function which should accept this object (EventListener) as
  * its first parameter and an EventNotification as its second.  The callback
  * should return TRUE if it was successful, FALSE on failure, or 'quit' to
  * break from the event listener loop.
  *
  * @param Closure|array Closure callback
  */
 public function listen($callback)
 {
     $this->sendReady();
     while (true) {
         if (!($input = trim($this->readLine()))) {
             continue;
         }
         $headers = EventNotification::parseData($input);
         $payload = fread($this->inputStream, (int) $headers['len']);
         $notification = new EventNotification($input, $payload, $headers);
         $result = call_user_func($callback, $this, $notification);
         if (true === $result) {
             $this->sendComplete();
         } else {
             if (false === $result) {
                 $this->sendFail();
             } else {
                 if ($result == 'quit') {
                     break;
                 }
             }
         }
         $this->sendReady();
     }
 }
 /**
  * Poll stdin for Supervisord notifications and dispatch notifications to
  * the callback function which should accept this object (EventListener) as
  * its first parameter and an EventNotification as its second.  The callback
  * should return TRUE if it was successful, FALSE on failure, or 'quit' to
  * break from the event listener loop.
  *
  * @param Closure|array Closure callback
  */
 public function listen($callback)
 {
     $this->sendReady();
     while (true) {
         if (!($input = trim($this->readLine()))) {
             continue;
         }
         $headers = EventNotification::parseData($input);
         // PHP 5.6 doesn't deal gracefully with this causing a buffer overflow
         $payload = '';
         if (isset($headers['len'])) {
             $payload = fread($this->inputStream, (int) $headers['len']);
         }
         $notification = new EventNotification($input, $payload, $headers);
         $result = call_user_func($callback, $this, $notification);
         if (true === $result) {
             $this->sendComplete();
         } else {
             if (false === $result) {
                 $this->sendFail();
             } else {
                 if ($result == 'quit') {
                     break;
                 }
             }
         }
         $this->sendReady();
     }
 }