Ejemplo n.º 1
0
 public function connect(Kernel $kernel)
 {
     $collection = new ControllerCollection();
     $collection->get("/favicon.ico", function ($request, $params) use($kernel) {
         // Memo: suppress error statistics
         return "";
     });
     return $collection;
 }
 public function connect(Kernel $kernel)
 {
     $container = $kernel->getContainer();
     $this->stat = $container['stat'];
     $collection = new ControllerCollection();
     $collection->get("/stat", function ($request, $params) use($kernel) {
         $buffer = "memory: " . memory_get_usage(true) . PHP_EOL;
         $stat = $this->stat;
         foreach ($stat as $key => $value) {
             $buffer .= sprintf("%s: %s" . PHP_EOL, $key, $value);
         }
         return $buffer;
     });
     return $collection;
 }
 public function connect(Kernel $kernel)
 {
     $container = $kernel->getContainer();
     $this->stat = $container['stat'];
     $collection = new ControllerCollection();
     $collection->get("/", function ($request, $params) use($kernel) {
         $container = $kernel->getContainer();
         $queue = $container['queue'];
         $config = $container['config'];
         if (isset($params['room_id']) && isset($params['msg'])) {
             if (count($queue) > $config['MAX_QUEUE_COUNT']) {
                 throw new \RuntimeException("Too many queues. please retry");
             }
             $queue->enqueue(array("room_id" => $params['room_id'], "msg" => $params['msg'], "address" => $request['peer']['address']));
             $this->stat->increment('message.enqueue', 1);
         } else {
             throw new \Exception("usage: /?room_id=ROOM_ID&msg=MESSAGE");
         }
         return "QUEUED";
     });
     return $collection;
 }