Skip to content

Commit

Permalink
Merge pull request #24 from psadaic/master
Browse files Browse the repository at this point in the history
enable ws server keep alive
  • Loading branch information
gcphost authored Apr 13, 2018
2 parents a19d069 + e756662 commit 1a9a5d3
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Console/Commands/RatchetServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ class RatchetServerCommand extends Command
*/
protected $driver;

/**
* Keep alive interval.
*
* @var int
*/
protected $keepAlive;

/**
* The ReactPHP event loop.
*
Expand All @@ -80,6 +87,11 @@ class RatchetServerCommand extends Command
*/
protected $ratchetServer;

/**
* WebSocket server instance.
*/
protected $wsServerInstance;

/**
* Get the console command options.
*
Expand All @@ -93,6 +105,7 @@ protected function getOptions()
['class', null, InputOption::VALUE_OPTIONAL, 'Class that implements MessageComponentInterface.', config('ratchet.class')],
['driver', null, InputOption::VALUE_OPTIONAL, 'Ratchet connection driver [IoServer|WsServer|WampServer]', 'WampServer'],
['zmq', 'z', null, 'Bind server to a ZeroMQ socket (always on for WampServer)'],
['keepAlive', null, InputOption::VALUE_OPTIONAL, 'Option to enable WebSocket server keep alive [interval in seconds]', config('ratchet.keepAlive', 0)],
];
}

Expand All @@ -109,6 +122,8 @@ public function handle()

$this->driver = $this->option('driver');

$this->keepAlive = $this->option('keepAlive');

$this->startServer();
}

Expand Down Expand Up @@ -165,10 +180,16 @@ private function bootWebSocketServer($withZmq = false)
$this->bootZmqConnection();
}

$this->wsServerInstance = new WsServer($this->serverInstance);

$this->serverInstance = new HttpServer(
new WsServer($this->serverInstance)
$this->wsServerInstance
);

if($this->keepAlive > 0){
$this->wsServerInstance->enableKeepAlive($this->getEventLoop(), $this->keepAlive);
}

return $this->bootIoServer();
}

Expand Down

0 comments on commit 1a9a5d3

Please sign in to comment.