getInstance() public static method

public static getInstance ( )
 /**
  * Called when the worker is ready to go.
  * @return void
  */
 public function onReady()
 {
     $appInstance = $this;
     // a reference to this application instance for ExampleWebSocketRoute
     // URI /exampleApp should be handled by ExampleWebSocketRoute
     WebSocketServer::getInstance()->addRoute('exampleApp', function ($client) use($appInstance) {
         return new ExampleWebSocketRoute($client, $appInstance);
     });
 }
Example #2
0
    {
        ob_start();
        $this->application->execute(array('swoole_socket', 'getfd'));
        $result = ob_get_contents();
        ob_end_clean();
        /*for($i=1 ; $i<= $result ; $i++) {
             	$server->push($i,'游客'.$frame->fd.'说:' .$frame->data);
         	}*/
        if ('smes_closed' == $frame->data) {
            $server->Close($frame->fd);
        } else {
            $result_fd = json_decode($result, true);
            foreach ($result_fd as $id => $fd) {
                $server->push($fd, '游客' . $frame->fd . '说:' . $frame->data);
            }
        }
    }
    public function onClose($server, $fd)
    {
        $this->application->execute(array('swoole_socket', 'removefd'), $fd);
    }
    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new WebSocketServer();
        }
        return self::$instance;
    }
}
WebSocketServer::getInstance();
Example #3
0
 /**
  * Called when the worker is ready to go.
  * @return void
  */
 public function onReady()
 {
     parent::onReady();
     $this->WS = WebSocketServer::getInstance();
 }