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


PHP Server::listen方法代码示例

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


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

示例1: start

 /**
  * Start the HTTP Server
  */
 public function start()
 {
     $this->httpServer->on('request', [$this, 'handleRequest']);
     $this->logger->info("Server is listening at " . $this->configuration['listen']['host'] . ":" . $this->configuration['listen']['port']);
     $this->socketServer->listen($this->configuration['listen']['port'], $this->configuration['listen']['host']);
     $this->eventLoop->run();
 }
开发者ID:thinframe,项目名称:server,代码行数:10,代码来源:Server.php

示例2: __construct

 /**
  * @param string        $httpHost HTTP hostname clients intend to connect to. MUST match JS `new WebSocket('ws://$httpHost');`
  * @param int           $port     Port to listen on. If 80, assuming production, Flash on 843 otherwise expecting Flash to be proxied through 8843
  * @param string        $address  IP address to bind to. Default is localhost/proxy only. '0.0.0.0' for any machine.
  * @param LoopInterface $loop     Specific React\EventLoop to bind the application to. null will create one for you.
  */
 public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null, $context = array())
 {
     if (extension_loaded('xdebug')) {
         trigger_error("XDebug extension detected. Remember to disable this if performance testing or going live!", E_USER_WARNING);
     }
     if (3 !== strlen('✓')) {
         throw new \DomainException('Bad encoding, length of unicode character ✓ should be 3. Ensure charset UTF-8 and check ini val mbstring.func_autoload');
     }
     if (null === $loop) {
         $loop = LoopFactory::create();
     }
     $this->httpHost = $httpHost;
     $socket = new Reactor($loop, $context);
     $socket->listen($port, $address);
     $this->routes = new RouteCollection();
     $this->_server = new IoServer(new HttpServer(new Router(new UrlMatcher($this->routes, new RequestContext()))), $socket, $loop);
     $policy = new FlashPolicy();
     if ('*' !== $httpHost) {
         $policy->addAllowedAccess($httpHost, 80);
         $policy->addAllowedAccess($httpHost, $port);
     }
     $flashSock = new Reactor($loop);
     $this->flashServer = new IoServer($policy, $flashSock);
     if (80 == $port) {
         $flashSock->listen(843, '0.0.0.0');
     } else {
         $flashSock->listen(8843);
     }
 }
开发者ID:Rudi9719,项目名称:stein-syn,代码行数:35,代码来源:App.php

示例3: __construct

 public function __construct($realmName, $loop = null, $bindAddress = '127.0.0.1', $port = 8181)
 {
     if ($loop === null) {
         $loop = Factory::create();
     }
     $this->bindAddress = $bindAddress;
     $this->port = $port;
     $this->realmName = $realmName;
     $this->socket = new Server($loop);
     $this->http = new \React\Http\Server($this->socket);
     $this->http->on('request', [$this, 'handleRequest']);
     $this->socket->listen($this->port, $bindAddress);
     parent::__construct($realmName, $loop);
 }
开发者ID:nepda,项目名称:WampPost,代码行数:14,代码来源:WampPost.php

示例4: setupServer

 /**
  * Sets up loop and server manually to allow periodic timer calls.
  */
 private function setupServer()
 {
     $this->setupApp();
     /** @var $loop \React\EventLoop\LoopInterface */
     $this->loop = \React\EventLoop\Factory::create();
     $this->socket = new Server($this->loop);
     if ($this->host) {
         $this->socket->listen($this->port, $this->host);
     } else {
         $this->socket->listen($this->port);
     }
     $this->setupPeriodicServices();
     $this->setupSocketListeners();
     $this->server = new \Ratchet\Server\IoServer($this->app, $this->socket, $this->loop);
 }
开发者ID:adamus-tork,项目名称:ClankBundle,代码行数:18,代码来源:WebSocketServerType.php

示例5: listen

 /**
  * @param int    $port
  * @param string $host
  */
 public function listen($port, $host)
 {
     $this->http->on('request', function (ReactRequest $request, ReactResponse $response) {
         return $this->onRequest($request, $response);
     });
     $this->logger->info("Phiremock http server listening on {$host}:{$port}");
     $this->socket->listen($port, $host);
     // Dispatch pending signals periodically
     if (function_exists('pcntl_signal_dispatch')) {
         $this->loop->addPeriodicTimer(0.5, function () {
             pcntl_signal_dispatch();
         });
     }
     $this->loop->run();
 }
开发者ID:mcustiel,项目名称:phiremock,代码行数:19,代码来源:ReactPhpServer.php

示例6: 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

示例7: __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

示例8: 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

示例9: listen

 /**
  * Creates a new \React\Http\Server and runs it
  *
  * @param int $port
  */
 public function listen($port)
 {
     $socket = new SocketServer($this->loop);
     $server = new HttpServer($socket);
     $server->on('request', $this->requestHandler);
     $socket->listen($port);
 }
开发者ID:voidcontext,项目名称:arc-reactor,代码行数:12,代码来源:ReactHttpServer.php

示例10: assertConnection

 public function assertConnection(array $options, $message = null)
 {
     $settings = array_merge(["ip" => "0.0.0.0", "port" => 0, "startServer" => false, "match" => true], $options);
     // optionally starting server
     if ($settings["startServer"]) {
         $serverLoop = EventLoopFactory::create();
         $server = new SocketServer($serverLoop);
         $server->listen($settings["port"]);
     }
     // client setup
     $clientLoop = EventLoopFactory::create();
     $dnsResolverFactory = new DnsResolverFactory();
     $dns = $dnsResolverFactory->createCached("8.8.8.8", $clientLoop);
     // dunno why dns is required for this shit
     $connector = new SocketConnector($clientLoop, $dns);
     $promise = $connector->create($settings["ip"], $settings["port"])->then(function (SocketStream $stream) {
         $stream->close();
         return true;
     }, function (SocketConnectionException $e) {
         return false;
     });
     $clientLoop->run();
     // catching the output
     $out = null;
     $promise->done(function ($v) use(&$out) {
         $out = $v;
     });
     // optionally cleaning up the server
     if ($settings["startServer"]) {
         $server->shutdown();
     }
     $this->assertEquals($out, $settings["match"], $message);
 }
开发者ID:ihsw,项目名称:toxiproxy-php-client,代码行数:33,代码来源:AbstractTest.php

示例11: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // create a log channel
     $log = new Logger('websocket');
     $log->pushHandler(new RotatingFileHandler(storage_path() . '/logs/websocket.log', 10, Logger::DEBUG));
     $config = Config::get('announcements-server');
     $loop = LoopFactory::create();
     $announcements = new AnnouncementsWebSocket($log);
     // Listen for the web server to make a message push.
     $broadcast = 'tcp://' . $config['broadcast']['ip'] . ':' . $config['broadcast']['port'];
     $this->info('Starting broadcast socket on ' . $broadcast);
     $context = new ZMQContext($loop);
     $broadcastSocket = $context->getSocket(ZMQ::SOCKET_PULL);
     $broadcastSocket->bind($broadcast);
     $broadcastSocket->on('message', array($announcements, 'onBroadcast'));
     // Listen for status check.
     $status = 'tcp://' . $config['status']['ip'] . ':' . $config['status']['port'];
     $this->info('Starting status socket on ' . $status);
     $statusSock = new SocketServer($loop);
     $statusSock->listen($config['status']['port'], $config['status']['ip']);
     new IoServer(new AnnouncementsServerStatus(), $statusSock);
     // Listen for WebSocket connections.
     $wsPort = $config['websocket']['port'];
     $wsIp = $config['websocket']['ip'];
     $this->info('Starting WebSocket socket on ws://' . $wsIp . ':' . $wsPort);
     $webSock = new SocketServer($loop);
     $webSock->listen($wsPort, $wsIp);
     new IoServer(new HttpServer(new WsServer($announcements)), $webSock);
     // Ping all clients each 2 min.
     $loop->addPeriodicTimer(120, function () use($announcements) {
         $announcements->ping();
     });
     $log->info('Server started');
     $loop->run();
 }
开发者ID:fencer-md,项目名称:stoticlle,代码行数:40,代码来源:AnnouncementsServer.php

示例12: setUpWebSocket

 /**
  * Set up our WebSocket server for clients wanting real-time updates
  *
  * @param StreamSelectLoop $loop
  * @return Ratchet\Server\IoServer
  */
 protected function setUpWebSocket(StreamSelectLoop $loop)
 {
     $webSock = new Server($loop);
     // Binding to 0.0.0.0 means remotes can connect
     $webSock->listen(static::SERVER_PORT, '0.0.0.0');
     return new IoServer(new HttpServer(new WsServer(new WampServer($this->pusher))), $webSock);
 }
开发者ID:admsa,项目名称:larachet,代码行数:13,代码来源:PushServer.php

示例13: 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

示例14: 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

示例15: __construct

 /**
  * Constructor
  *
  * @param OutputInterface $output  Output
  * @param string          $docroot Docroot
  * @param string          $env     Environment
  * @param bool            $debug   Debug
  * @param int             $port    Port
  */
 public function __construct(OutputInterface $output, $docroot, $env, $debug, $port = null)
 {
     $repository = new PhpRepository();
     if (!$port) {
         $port = 8000;
     }
     $this->output = $output;
     $this->env = $env;
     $this->debug = $debug;
     $this->port = $port;
     $this->loop = new StreamSelectLoop();
     $socketServer = new ReactSocketServer($this->loop);
     $httpServer = new ReactHttpServer($socketServer);
     $httpServer->on("request", function ($request, $response) use($repository, $docroot, $output) {
         $path = $docroot . '/' . ltrim(rawurldecode($request->getPath()), '/');
         if (is_dir($path)) {
             $path .= '/index.html';
         }
         if (!file_exists($path)) {
             HttpServer::logRequest($output, 404, $request);
             $response->writeHead(404, ['Content-Type' => 'text/html']);
             return $response->end(implode('', ['<h1>404</h1>', '<h2>Not Found</h2>', '<p>', 'The embedded <a href="https://sculpin.io">Sculpin</a> web server could not find the requested resource.', '</p>']));
         }
         $type = 'application/octet-stream';
         if ('' !== ($extension = pathinfo($path, PATHINFO_EXTENSION))) {
             if ($guessedType = $repository->findType($extension)) {
                 $type = $guessedType;
             }
         }
         HttpServer::logRequest($output, 200, $request);
         $response->writeHead(200, array("Content-Type" => $type));
         $response->end(file_get_contents($path));
     });
     $socketServer->listen($port, '0.0.0.0');
 }
开发者ID:georgjaehnig,项目名称:sculpin,代码行数:44,代码来源:HttpServer.php


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