本文整理汇总了PHP中Ratchet\Server\IoServer::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP IoServer::factory方法的具体用法?PHP IoServer::factory怎么用?PHP IoServer::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ratchet\Server\IoServer
的用法示例。
在下文中一共展示了IoServer::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$port = env('SOCKET_PORT');
$this->info('Websocket is running on port ' . $port);
$server = IoServer::factory(new HttpServer(new WsServer(new \App\Services\Websocket())), $port);
$server->run();
}
示例2: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Starting web socket server...');
$this->server = IoServer::factory(new HttpServer(new WsServer(new Chat())), 8080, '0.0.0.0');
$this->info('To stop the web socket server press "Ctrl" + "C"');
$this->server->run();
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$chat = $this->getContainer()->get('chat');
$server = IoServer::factory(new HttpServer(new WsServer($chat)), 8080);
$server->run();
echo "Server started";
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
declare (ticks=1);
register_shutdown_function(array($this, 'stopCommand'));
set_error_handler(array($this, 'errorHandler'));
if (function_exists("pcntl_signal")) {
pcntl_signal(SIGTERM, [$this, 'stopCommand']);
pcntl_signal(SIGINT, [$this, 'stopCommand']);
} else {
}
$this->isDebug = $input->getArgument('isDebug');
$port = $input->getOption('port');
$chat = $this->container->get('app.chat.handler');
$chat->setIsDebug($this->isDebug);
$messageManager = new MessageManager($chat);
$messageManager->setIsDebug($this->isDebug);
$server = IoServer::factory(new HttpServer(new WsServer($messageManager)), $port);
if ($this->isDebug) {
$redis = $this->container->get('snc_redis.default');
$server->loop->addPeriodicTimer(5, function () use($redis, $messageManager) {
$memory = memory_get_usage();
echo "Send messages. Redis value: " . $redis->get('value') . "\r\n";
$info = array();
$info['message'] = "Redis value: " . $redis->get('value') . "; Memory: " . $memory;
$info['type'] = 'message';
$info['from'] = 'me';
$messageManager->sendAll(json_encode($info));
});
}
$this->logMessage("Start server.");
$server->run();
$this->logMessage("Finish execute daemon.");
}
示例5: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$port = intval($this->option('port'));
$this->info("Starting chat web socket server on port " . $port);
$server = IoServer::factory(new HttpServer(new WsServer(new Chat())), 8082);
$server->run();
}
示例6: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$port = intval($this->argument('port'));
$this->info("Starting chat web socket server on port " . $port);
$server = IoServer::factory(new HttpServer(new WsServer(new ChatController())), $port);
$server->run();
}
示例7: execute
public function execute(InputInterface $input, OutputInterface $output)
{
/**
* @var \Symfony\Component\Console\Helper\FormatterHelper
*/
$formatter = $this->getHelper('formatter');
$output->writeln($formatter->formatSection('IO', 'Start development server'));
// $loop = \React\EventLoop\Factory::create();
$bridgeName = $input->getOption('bridge');
switch (strtolower($bridgeName)) {
case 'phalcony':
$bridge = new Phalcony();
break;
case 'hello':
default:
$bridge = new SimpleBridge();
break;
}
$bridge->on('open', function (ConnectionInterface $conn, RequestInterface $request = null) use(&$formatter, $output) {
$section = $formatter->formatSection('IO', 'Connection is open from ' . $request->getHost() . ' on ' . date('h:i:s') . ' : ' . $request->getUrl());
$output->writeln($section);
});
$bridge->on('close', function (ConnectionInterface $conn, $timer) use(&$formatter, $output) {
$output->writeln($formatter->formatSection('IO', sprintf('Connection is closed. Request completed %.4F sec.', $timer)));
});
$bridge->on('error', function (Exception $e) use(&$formatter, $output) {
$output->writeln($formatter->formatBlock(array('[App]', $e->getMessage(), 'in the ' . $e->getFile() . ' file on ' . $e->getLine() . ' line'), 'error'));
});
$listen = $input->getOption('listen');
$port = $input->getOption('port');
$server = IoServer::factory(new HttpServer($bridge), $port, $listen);
$server->run();
}
示例8: run
/**
* @param AbstractMultiRoomServer $chatServer
* @param int $port
* @param string $ip
* @return IoServer
*/
public static function run(AbstractMultiRoomServer $chatServer, $port, $ip = '0.0.0.0')
{
$wsServer = new WsServer($chatServer);
$http = new HttpServer($wsServer);
$server = IoServer::factory($http, $port, $ip);
$server->run();
return $server;
}
示例9: run
/**
* @param Chat $chatServer
* @param int $port
* @param string $ip
* @return IoServer
*/
public static function run(Chat $chatServer, $port, $ip = '127.0.0.1')
{
$wsServer = new WsServer($chatServer);
$http = new HttpServer($wsServer);
$server = IoServer::factory($http, $port, $ip);
$server->run();
return $server;
}
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$port = $input->getOption('port');
$address = $input->getOption('address');
$server = IoServer::factory(new HttpServer(new WsServer(new Server($this->getContainer()->get('croupier')))), $port, $address);
$output->writeln(sprintf('<info>Starting Croupier server on %s:%d.</info>', $address, $port));
$server->run();
}
示例11: startServer
private function startServer()
{
$ip = $this->config['server']['host'];
$port = $this->config['server']['port'];
$server = IoServer::factory(new HttpServer(new WsServer(new \Fr\DiffSocket\Server($this->config))), $port, $ip);
echo "Server started on {$ip}:{$port}\n";
$server->run();
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
//$chat = $this->getContainer()->get('heliosblog.chat');
$memcache = new \Memcache();
$memcache->connect('localhost', 11211);
$server = IoServer::factory(new HttpServer(new WsServer(new SessionProvider(new Chat1(), new Handler\MemcacheSessionHandler($memcache)))), 8080);
echo "Chat server is running\n";
$server->run();
}
示例13: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$address = $this->option('address');
$port = intval($this->option('port'));
$this->info('Starting web socket server on port ' . $port);
$server = IoServer::factory(new HttpServer(new WsServer($this->connection)), $port, $address);
$this->connection->setServer($server);
$server->run();
}
示例14: newWorker
public function newWorker($output, $formatter, $listen, $port, $bridge)
{
$pid = pcntl_fork();
if (!$pid) {
$output->writeln($formatter->formatSection('App', 'Start slave worker on ' . $listen . ':' . $port . ' pid: ' . $pid));
$this->slots[] = $server = IoServer::factory(new HttpServer($bridge), $port, $listen);
$server->run();
}
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$port = $input->getOption('port');
if (!$port) {
$port = 4567;
}
$server = IoServer::factory(new HttpServer(new WsServer($this->getContainer()->get('tetris.socket_server'))), $port);
$output->writeln("Server running on port {$port}");
$server->run();
}