当前位置: 首页>>代码示例>>PHP>>正文


PHP Server::on方法代码示例

本文整理汇总了PHP中React\Socket\Server::on方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::on方法的具体用法?PHP Server::on怎么用?PHP Server::on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在React\Socket\Server的用法示例。


在下文中一共展示了Server::on方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setupSocketListeners

 private function setupSocketListeners()
 {
     $connectionListeners = array();
     foreach ($this->socketListeners as $listener) {
         /** @var SocketListenerInterface $service */
         $service = $this->getContainer()->get($listener);
         if (!$service instanceof SocketListenerInterface) {
             throw new \Exception("Socket Listener Services must implement JDare/ClankBundle/Server/SocketListenerInterface");
         }
         foreach ((array) $service->getListeners() as $event => $callback) {
             if ($event == 'connection') {
                 $this->socket->on('connection', $callback);
             } elseif ($event == 'error') {
                 $this->socket->on('error', $callback);
             } else {
                 if (!isset($connectionListeners[$event])) {
                     $connectionListeners[$event] = array();
                 }
                 $connectionListeners[$event][] = $callback;
             }
         }
     }
     if (!empty($connectionListeners)) {
         $this->socket->on('connection', function (ConnectionInterface $conn) use(&$connectionListeners) {
             $conn->on('data', function ($data) use($conn, &$connectionListeners) {
                 if (isset($connectionListeners[$data])) {
                     foreach ($connectionListeners[$data] as $callback) {
                         $callback($conn);
                     }
                 }
             });
         });
     }
 }
开发者ID:adamus-tork,项目名称:ClankBundle,代码行数:34,代码来源:WebSocketServerType.php

示例2: __construct

 /**
  * @param int $port
  * @param string $host
  */
 public function __construct($port, $host = '127.0.0.1')
 {
     $this->host = $host;
     $this->port = $port;
     $this->loop = LoopFactory::create();
     $this->socket = new SocketServer($this->loop);
     $this->socket->on('connection', array($this, 'onConnection'));
 }
开发者ID:xing393939,项目名称:Laravel-5-Bootstrap-3-Starter-Site,代码行数:12,代码来源:Server.php

示例3: start

 public function start()
 {
     $loop = React\EventLoop\Factory::create();
     $socket = new React\Socket\Server($loop);
     $server = $this;
     $socket->on(self::CONNECTION, function (React\Socket\Connection $connection) use(&$server) {
         $server->connectionEvent($connection);
         $connection->on(SyncDaemonServer::DATA, function ($data) use(&$connection, &$server) {
             list($command, $name) = explode(' ', $data);
             if ($command == SyncDaemonServer::ACQUIRE) {
                 $server->acquireCommand($connection, $name);
             }
             if ($command == SyncDaemonServer::RELEASE) {
                 $server->releaseCommand($connection, $name);
             }
         });
         $connection->on(SyncDaemonServer::CLOSE, function () use(&$connection, &$server) {
             $server->closeEvent($connection);
         });
         $connection->write(SyncDaemonServer::ACCEPT);
     });
     //debug
     //$loop->addPeriodicTimer(1, function () use (&$server) {
     //    var_dump(count($server->connections) . '-' . count($server->locks));
     //});
     $socket->listen($this->port, $this->host);
     $loop->run();
 }
开发者ID:ivixlabs,项目名称:sync-daemon,代码行数:28,代码来源:SyncDaemonServer.php

示例4: __construct

 public function __construct(QueueContextInterface $queueContext, LoopInterface $eventLoop, $port)
 {
     $this->queueContext = $queueContext;
     $server = new Server($eventLoop);
     $server->on('connection', [$this, 'onConnection']);
     $server->listen($port);
 }
开发者ID:PHPQ,项目名称:Server,代码行数:7,代码来源:ProducerServer.php

示例5: run

 /**
  * Starts the main loop. Blocks.
  */
 public function run()
 {
     Debug::enable();
     //make whatever is necessary to disable all stuff that could buffer output
     ini_set('zlib.output_compression', 0);
     ini_set('output_buffering', 0);
     ini_set('implicit_flush', 1);
     ob_implicit_flush(1);
     $this->loop = \React\EventLoop\Factory::create();
     $this->controller = new React\Server($this->loop);
     $this->controller->on('connection', array($this, 'onSlaveConnection'));
     $this->controllerHost = $this->getNewControllerHost();
     $this->controller->listen(5500, $this->controllerHost);
     $this->web = new \React\Socket\Server($this->loop);
     $this->web->on('connection', array($this, 'onWeb'));
     $this->web->listen($this->port, $this->host);
     $this->tcpConnector = new \React\SocketClient\TcpConnector($this->loop);
     $pcntl = new \MKraemer\ReactPCNTL\PCNTL($this->loop);
     $pcntl->on(SIGTERM, [$this, 'shutdown']);
     $pcntl->on(SIGINT, [$this, 'shutdown']);
     $pcntl->on(SIGCHLD, [$this, 'handleSigchld']);
     $pcntl->on(SIGUSR1, [$this, 'restartWorker']);
     if ($this->isDebug()) {
         $this->loop->addPeriodicTimer(0.5, function () {
             $this->checkChangedFiles();
         });
     }
     $this->isRunning = true;
     $loopClass = (new \ReflectionClass($this->loop))->getShortName();
     $this->output->writeln("<info>Starting PHP-PM with {$this->slaveCount} workers, using {$loopClass} ...</info>");
     for ($i = 0; $i < $this->slaveCount; $i++) {
         $this->newInstance(5501 + $i);
     }
     $this->loop->run();
 }
开发者ID:php-pm,项目名称:php-pm,代码行数:38,代码来源:ProcessManager.php

示例6: addListener

 public function addListener($host = '127.0.0.1', $port = 8080, $use_ssl = false, $cert = null)
 {
     $proxy = new Server($this->loop);
     $proxy->on('connection', new ConnectionHandler($this));
     $context = !$use_ssl ? [] : ['ssl' => ['local_cert' => $cert === null ? __DIR__ . '/../certificate.pem' : $cert, 'allow_self_signed' => true, 'verify_peer' => false]];
     $proxy->listen($port, $host, $context);
 }
开发者ID:mpyw,项目名称:php-hyper-builtin-server,代码行数:7,代码来源:Master.php

示例7: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Make sure that websockets are enabled in the config so that the proper
     // session storage handler is used
     if (!$this->getContainer()->getParameter('bzion.features.websocket.enabled')) {
         $message = "You need to enable websockets in your config before using the push server";
         $output->writeln("<bg=red;options=bold>\n\n [ERROR] {$message}\n</>");
         return;
     }
     $loop = EventLoopFactory::create();
     $pusher = new EventPusher($loop, $output);
     $pushPort = $input->getOption('push') ?: $this->getContainer()->getParameter('bzion.features.websocket.push_port');
     $pullPort = $input->getOption('pull') ?: $this->getContainer()->getParameter('bzion.features.websocket.pull_port');
     $pullSocket = new Server($loop);
     $pullSocket->on('connection', function ($conn) use($pusher) {
         $conn->on('data', function ($data) use($pusher) {
             $pusher->onServerEvent(json_decode($data));
         });
     });
     // Bind to 127.0.0.1, so that only the server can send messages to the socket
     $pullSocket->listen($pullPort, '127.0.0.1');
     $output->writeln(" <fg=green>Running pull service on port {$pullPort}</>");
     $session = new SessionProvider($pusher, new DatabaseSessionHandler());
     $pushSocket = new Server($loop);
     $webServer = new IoServer(new WsServer($session), $pushSocket);
     // Binding to 0.0.0.0 means remotes can connect
     $pushSocket->listen($pushPort, '0.0.0.0');
     $output->writeln(" <fg=green>Running push service on port {$pushPort}</>");
     $output->writeln("\n <bg=green;options=bold>Welcome to the BZiON live notification server!</>");
     $loop->run();
 }
开发者ID:blast007,项目名称:bzion,代码行数:31,代码来源:ServerCommand.php

示例8: run

 /**
  * Starts the main loop. Blocks.
  */
 public function run()
 {
     Debug::enable();
     gc_disable();
     //necessary, since connections will be dropped without reasons after several hundred connections.
     $this->loop = \React\EventLoop\Factory::create();
     $this->controller = new \React\Socket\Server($this->loop);
     $this->controller->on('connection', array($this, 'onSlaveConnection'));
     $this->controller->listen(5500);
     $this->web = new \React\Socket\Server($this->loop);
     $this->web->on('connection', array($this, 'onWeb'));
     $this->web->listen($this->port, $this->host);
     $this->tcpConnector = new \React\SocketClient\TcpConnector($this->loop);
     $pcntl = new \MKraemer\ReactPCNTL\PCNTL($this->loop);
     $pcntl->on(SIGTERM, [$this, 'shutdown']);
     $pcntl->on(SIGINT, [$this, 'shutdown']);
     if ($this->isDebug()) {
         $this->loop->addPeriodicTimer(0.5, function () {
             $this->checkChangedFiles();
         });
     }
     $this->isRunning = true;
     $loopClass = (new \ReflectionClass($this->loop))->getShortName();
     $this->output->writeln("<info>Starting PHP-PM with {$this->slaveCount} workers, using {$loopClass} ...</info>");
     for ($i = 0; $i < $this->slaveCount; $i++) {
         $this->newInstance(5501 + $i);
     }
     $this->loop->run();
 }
开发者ID:marcj,项目名称:php-pm,代码行数:32,代码来源:ProcessManager.php

示例9: connectionToIp6TcpServerShouldSucceed

 /** @test */
 public function connectionToIp6TcpServerShouldSucceed()
 {
     $capturedStream = null;
     $loop = new StreamSelectLoop();
     $server = new Server($loop);
     $server->on('connection', $this->expectCallableOnce());
     $server->on('connection', array($server, 'shutdown'));
     $server->listen(9999, '::1');
     $connector = new TcpConnector($loop);
     $connector->create('::1', 9999)->then(function ($stream) use(&$capturedStream) {
         $capturedStream = $stream;
         $stream->end();
     });
     $loop->run();
     $this->assertInstanceOf('React\\Stream\\Stream', $capturedStream);
 }
开发者ID:gai00,项目名称:socket-client,代码行数:17,代码来源:TcpConnectorTest.php

示例10: __construct

 /**
  * @param NetworkAddressInterface $localAddr
  * @param MessageFactory $messageFactory
  * @param Server $server
  * @param LoopInterface $loop
  */
 public function __construct(NetworkAddressInterface $localAddr, MessageFactory $messageFactory, Server $server, LoopInterface $loop)
 {
     $this->local = $localAddr;
     $this->messageFactory = $messageFactory;
     $this->server = $server;
     $this->loop = $loop;
     $server->on('connection', [$this, 'handleIncomingPeer']);
 }
开发者ID:tokenly,项目名称:bitcoin-p2p-php,代码行数:14,代码来源:Listener.php

示例11: __construct

 /**
  * Listener constructor.
  * @param ConnectionParams $params
  * @param MessageFactory $messageFactory
  * @param Server $server
  * @param LoopInterface $loop
  */
 public function __construct(ConnectionParams $params, MessageFactory $messageFactory, Server $server, LoopInterface $loop)
 {
     $this->params = $params;
     $this->messageFactory = $messageFactory;
     $this->server = $server;
     $this->loop = $loop;
     $server->on('connection', [$this, 'handleIncomingPeer']);
 }
开发者ID:Bit-Wasp,项目名称:bitcoin-p2p-php,代码行数:15,代码来源:Listener.php

示例12: handleRouterStart

 public function handleRouterStart(RouterStartEvent $event)
 {
     $socket = new Server($this->loop);
     $socket->on('connection', [$this, "handleConnection"]);
     Logger::info($this, "Raw socket listening on " . $this->address . ":" . $this->port);
     $socket->listen($this->port, $this->address);
     $this->server = $socket;
 }
开发者ID:voryx,项目名称:thruway,代码行数:8,代码来源:RawSocketTransportProvider.php

示例13: startTransportProvider

 /**
  * Start transport provider
  *
  * @param \Thruway\Peer\AbstractPeer $peer
  * @param \React\EventLoop\LoopInterface $loop
  */
 public function startTransportProvider(AbstractPeer $peer, LoopInterface $loop)
 {
     $this->peer = $peer;
     $this->loop = $loop;
     $socket = new Server($loop);
     $socket->on('connection', [$this, "handleConnection"]);
     $socket->listen($this->port, $this->address);
 }
开发者ID:pacho104,项目名称:redbpim,代码行数:14,代码来源:RawSocketTransportProvider.php

示例14: listen

 public function listen($port)
 {
     $server = new SocketServer($this->loop);
     $server->on('connection', function (SocketConnection $connection) {
         try {
             $this->connectionManager->accept($connection);
         } catch (\Exception $e) {
             $this->logger->error('Connection failed', ['error' => $e->getMessage()]);
         }
     });
     $server->listen($port, '0.0.0.0');
     $this->logger->info('Started socket server', ['port' => $port]);
 }
开发者ID:proof,项目名称:blackjack-php-server,代码行数:13,代码来源:Server.php

示例15: run

 public function run()
 {
     $this->loop = \React\EventLoop\Factory::create();
     $this->controller = new \React\Socket\Server($this->loop);
     $this->controller->on('connection', array($this, 'onSlaveConnection'));
     $this->controller->listen(5500);
     $this->web = new \React\Socket\Server($this->loop);
     $this->web->on('connection', array($this, 'onWeb'));
     $this->web->listen($this->port, $this->host);
     for ($i = 0; $i < $this->slaveCount; $i++) {
         $this->newInstance();
     }
     $this->run = true;
     $this->loop();
 }
开发者ID:ravismula,项目名称:php-pm,代码行数:15,代码来源:ProcessManager.php


注:本文中的React\Socket\Server::on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。