Inheritance: extends PHPDaemon\Network\Server, use trait PHPDaemon\Traits\EventHandlers
Example #1
4
 /**
  * Called when the worker is ready to go.
  * @return void
  */
 public function onReady()
 {
     $appInstance = $this;
     // a reference to this application instance for ExampleWebSocketRoute
     \PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute('ExamplePubSub', function ($client) use($appInstance) {
         return new ExamplePubSubWebSocketRoute($client, $appInstance);
     });
     $this->sql = \PHPDaemon\Clients\MySQL\Pool::getInstance();
     $this->pubsub = new \PHPDaemon\PubSub\PubSub();
     $this->pubsub->addEvent('usersNum', \PHPDaemon\PubSub\PubSubEvent::init()->onActivation(function ($pubsub) use($appInstance) {
         \PHPDaemon\Core\Daemon::log('onActivation');
         if (isset($pubsub->event)) {
             \PHPDaemon\Core\Timer::setTimeout($pubsub->event, 0);
             return;
         }
         $pubsub->event = setTimeout(function ($timer) use($pubsub, $appInstance) {
             $appInstance->sql->getConnection(function ($sql) use($pubsub) {
                 if (!$sql->connected) {
                     return;
                 }
                 $sql->query('SELECT COUNT(*) `num` FROM `dle_users`', function ($sql, $success) use($pubsub) {
                     $pubsub->pub(sizeof($sql->resultRows) ? $sql->resultRows[0]['num'] : 'null');
                 });
             });
             $timer->timeout(5000000.0);
             // 5 seconds
         }, 0);
     })->onDeactivation(function ($pubsub) {
         if (isset($pubsub->event)) {
             \PHPDaemon\Core\Timer::cancelTimeout($pubsub->event);
         }
     }));
 }
 public function initRoutes()
 {
     $appInstance = $this;
     $path = '';
     \PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute($path, function ($client) use($path, $appInstance) {
         return $appInstance->getRoute($path, $client);
     });
 }
Example #3
0
 /**
  * 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
     \PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute('exampleApp', function ($client) use($appInstance) {
         return new ExampleWebSocketRoute($client, $appInstance);
     });
 }
 /**
  * Called when the worker is ready to go.
  * @return void
  */
 public function onReady()
 {
     $_ws = \PHPDaemon\Servers\WebSocket\Pool::getInstance();
     $_ws->addRoute('/sockjs', function ($client) {
         Daemon::log('call route at WebSocket Server');
         //Daemon::log($client);
         return new \SockJsAppRoute($client, $this);
     });
     $this->log('onReady at SockJsApp');
 }
Example #5
0
 /**
  * Called when the worker is ready to go.
  * @return void
  */
 public function onReady()
 {
     $ws = WebSocketPool::getInstance($this->config->wssname->value);
     $ws->addRoute('close', function ($client) {
         return new Close($client, $this);
     });
     $ws->addRoute('echo', function ($client) {
         return new EchoFeed($client, $this);
     });
     $ws->addRoute('disabled_websocket_echo', function ($client) {
         return new EchoFeed($client, $this);
     });
     $ws->setRouteOptions('disabled_websocket_echo', ['websocket' => false]);
     $ws->addRoute('cookie_needed_echo', function ($client) {
         return new EchoFeed($client, $this);
     });
     $ws->setRouteOptions('cookie_needed_echo', ['cookie_needed' => true]);
 }
Example #6
0
 /**
  * Called when the worker is ready to go
  * @return void
  */
 public function onReady()
 {
     $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance($this->config->redisname->value);
     $this->sessions = new ObjectStorage();
     $this->wss = new ObjectStorage();
     foreach (preg_split('~\\s*;\\s*~', $this->config->wssname->value) as $wssname) {
         $this->attachWss(WebSocketPool::getInstance(trim($wssname)));
     }
 }
Example #7
0
 public function onReady()
 {
     if ($this->config->enable->value) {
         $this->WS = \PHPDaemon\Servers\WebSocket\Pool::getInstance();
         if ($this->WS) {
             $this->WS->addRoute('MUChat', array($this, 'onHandshake'));
         }
         $appInstance = $this;
         $req = new MsgQueueRequest($this, $this);
         $req = new IdleCheck($appInstance, $appInstance);
         $this->LockClient = \PHPDaemon\Clients\Lock\Pool::getInstance();
         $this->LockClient->job(__CLASS__, true, function ($jobname) use($appInstance) {
             $appInstance->pushRequest(new UpdateStat($appInstance, $appInstance));
         });
     }
 }
Example #8
0
 /**
  * Called when the worker is ready to go.
  * @return void
  */
 public function onReady()
 {
     \PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute('/sockjs', function ($client) {
         return new SimpleRoute($client, $this);
     });
 }
Example #9
0
 /**
  * Called when the worker is ready to go.
  * @return void
  */
 public function onReady()
 {
     parent::onReady();
     $this->WS = \PHPDaemon\Servers\WebSocket\Pool::getInstance($this->config->wssname->value, false);
 }
Example #10
0
 public function onReady()
 {
     if ($this->isEnabled()) {
         \PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute('Chat', array($this, 'onHandshake'));
         $app = $this;
         $this->timer = setTimeout(function ($timer) use($app) {
             foreach ($app->tags as $tag) {
                 $tag->touch();
             }
             $timer->timeout();
         }, 300000.0);
     }
 }