Example #1
0
 /**
  * Initialize a new stream listener
  */
 public function __construct($stream)
 {
     $this->stream = $stream;
     stream_set_blocking($this->stream, 0);
     $meta = stream_get_meta_data($this->stream);
     if (substr($meta['mode'], -1) === '+') {
         $this->writable = true;
         $this->readable = true;
     } else {
         if (strpos($meta['mode'], 'r') !== false) {
             $this->readable = true;
         }
         if (strpos($meta['mode'], 'w') !== false) {
             $this->writable = true;
         }
     }
     if ($this->readable) {
         $this->ev_read = event_new();
         event_set($this->ev_read, $this->stream, EV_READ | EV_PERSIST, array($this, '_read'));
         Loop::attachEvent($this->ev_read);
     }
     if ($this->writable) {
         $this->ev_write = event_new();
         event_set($this->ev_write, $this->stream, EV_WRITE | EV_PERSIST, array($this, '_write'));
         Loop::attachEvent($this->ev_write);
     }
 }
Example #2
0
 /**
  * Initialize a new stream listener
  */
 public function __construct($fn, $interval)
 {
     $this->fn = $fn;
     $this->interval = $interval;
     $this->event = event_timer_new();
     event_timer_set($this->event, array($this, 'tick'));
     Loop::attachEvent($this->event, $this->interval * 1000);
 }