Esempio n. 1
0
 /**
  * Run main bot process
  */
 public function run()
 {
     $this->prepareOnMessage();
     $this->preparePeriodicCommands();
     $this->connect();
     $this->loop->run();
 }
Esempio n. 2
0
 public function getStatus(callable $callback)
 {
     $this->request('status', [], function ($result) use($callback) {
         $callback(json_decode($result, true));
     });
     $this->loop->run();
 }
Esempio n. 3
0
 /**
  * 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();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->client->getUsers()->then(function ($users) use($output) {
         $this->importUsers($users, $output);
     });
     $this->loop->run();
 }
Esempio n. 5
0
 /**
  * Run the application by entering the event loop
  * @throws \RuntimeException If a loop was not previously specified
  */
 public function run()
 {
     if (null === $this->loop) {
         throw new \RuntimeException("A React Loop was not provided during instantiation");
     }
     // @codeCoverageIgnoreStart
     $this->loop->run();
     // @codeCoverageIgnoreEnd
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function start(ServerContextInterface $context, RequestHandlerInterface $requestHandler)
 {
     $this->loop = Factory::create();
     $this->socketServer = new SocketServer($this->loop);
     $this->httpServer = new HttpServer($this->socketServer);
     $this->httpServer->on('request', $this->createRequestHandler($requestHandler));
     $this->socketServer->listen($context->getListenPort(), $context->getListenAddress());
     $this->loop->run();
 }
Esempio n. 7
0
 /**
  * @param array $options
  * @param array $arguments
  * @return mixed
  */
 public function run(array $options, array $arguments)
 {
     $port = isset($arguments[0]) ? $arguments[0] : "8001";
     $host = isset($arguments[1]) ? $arguments[1] : "0.0.0.0";
     /** @var \Castle23\Http\Server $server */
     $server = $this->container->getInstanceOf(Server::class);
     $this->socket->listen($port, $host);
     $this->loop->run();
 }
Esempio n. 8
0
 public function run()
 {
     $this->processes = $this->stdout = $this->runtimes = $this->results = [];
     $this->process_id = 0;
     while (count($this->processes) < $this->cpus) {
         $this->queueProcess();
     }
     $this->loop->run();
     $this->calculateResults();
 }
Esempio n. 9
0
 /**
  * Starts the websocket server
  *
  * @return void
  */
 public function start()
 {
     $this->__loop = LoopFactory::create();
     if ($this->__loop instanceof \React\EventLoop\StreamSelectLoop) {
         $this->out('<warning>Your configuration doesn\'t seem to support \'ext-libevent\'. It is highly reccomended that you install and configure it as it provides significant performance gains over stream select!</warning>');
     }
     $socket = new Reactor($this->__loop);
     $socket->listen(Configure::read('Ratchet.Connection.websocket.port'), Configure::read('Ratchet.Connection.websocket.address'));
     $this->__ioServer = new IoServer(new HttpServer(new WsServer(new SessionProvider(new WampServer(new CakeWampAppServer($this, $this->__loop, CakeEventManager::instance(), $this->params['verbose'])), new CakeWampSessionHandler(), [], new PhpSerializeHandler()))), $socket, $this->__loop);
     $this->__loop->run();
 }
Esempio n. 10
0
 public function start()
 {
     $this->loop = \WyriHaximus\Ratchet\loopResolver();
     $router = new Router($this->loop);
     $router->addInternalClient(new InternalClient('first', $this->loop));
     $router->addTransportProvider(new RatchetTransportProvider(Configure::read('WyriHaximus.Ratchet.Connection.Websocket.address'), Configure::read('WyriHaximus.Ratchet.Connection.Websocket.port')));
     //$router->getRealmManager()->setDefaultAuthorizationManager(new AllPermissiveAuthorizationManager());
     EventManager::instance()->dispatch(WebsocketStartEvent::create($this->loop));
     $router->start(false);
     $this->loop->run();
 }
Esempio n. 11
0
 /**
  * Runs the message server on the given port.
  *
  * @param string  $consumer Command to execute when a message arrives
  * @param integer $port     Port to run the server on
  *
  * @return void
  */
 public function run($consumer, $port, $callback = null)
 {
     // @codeCoverageIgnoreStart
     $this->socket->on('connection', function (ConnectionInterface $conn) use($consumer, $callback) {
         $conn->on('data', function ($data) use($conn, $consumer, $callback) {
             $this->handleData(trim($data), $consumer, $conn, $callback);
         });
     });
     // @codeCoverageIgnoreEnd
     $this->socket->listen($port);
     $this->loop->run();
 }
Esempio n. 12
0
 /**
  * Start the websocket server
  */
 public function start()
 {
     $this->__loop = Factory::create();
     $pusher = new CakeWampAppServer();
     $context = new Context($this->__loop);
     $pull = $context->getSocket(ZMQ::SOCKET_PULL);
     $pull->bind("tcp://" . Configure::read('CakeRatchet.ZMQServer.host') . ":" . Configure::read('CakeRatchet.ZMQServer.port'));
     $pull->on('message', array($pusher, 'onBlogEntry'));
     $webSock = new Server($this->__loop);
     $webSock->listen(Configure::read('CakeRatchet.Server.port'), Configure::read('CakeRatchet.Server.host'));
     $this->__ioServer = new IoServer(new HttpServer(new WsServer(new WampServer($pusher))), $webSock);
     $this->__loop->run();
 }
Esempio n. 13
0
 /**
  * Run react.
  *
  * @param int    $port
  * @param string $host
  */
 public function run($port, $host)
 {
     $request_handler = function (Request $request, Response $response) {
         echo $request->getMethod() . ' ' . $request->getPath() . PHP_EOL;
         $sf_request = $this->request_bridge->convertRequest($request);
         $sf_response = $this->app->handle($sf_request);
         $this->app->terminate($sf_request, $sf_response);
         $this->response_bridge->send($response, $sf_response);
     };
     $this->http->on('request', $request_handler);
     $this->socket->listen($port, $host);
     $this->loop->run();
 }
 /**
  * @test
  */
 public function itReadsToEnd()
 {
     $handle = $this->wrap(fopen('php://temp', 'w+'));
     fwrite($handle, 'data');
     async_stream_register_write($handle, function ($handle) {
         fseek($handle, 0);
         $this->assertFalse(feof($handle));
         fread($handle, 4);
         $this->assertTrue(feof($handle));
         fclose($handle);
     });
     $this->loop->run();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $client = $this->client;
     $client->on('message', function (Payload $payload) use($output) {
         $this->onMessage($payload, $output);
     });
     $client->on('reaction_added', function (Payload $payload) use($client, $output) {
         $this->onReaction($payload, $output);
     });
     $client->connect()->then(function () use($client, $output) {
         $output->writeln('<info>Connected</info>');
     });
     $this->loop->run();
 }
Esempio n. 16
0
 /**
  * @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();
 }
Esempio n. 17
0
 /**
  * Start manager loop
  */
 private function startLoop()
 {
     $this->client = $this->stompFactory->createClient();
     $this->client->connect()->then(function (Client $client) {
         $this->loop->addPeriodicTimer(self::PROVISION_TIME, function () {
             $this->provision();
         });
         $client->subscribe($this->channel, function (Frame $frame) use($client) {
             try {
                 $request = $this->messageTransformer->decodeRequest($frame->body);
                 $closure = $request->getClosure();
                 if (!is_callable($closure)) {
                     throw new ManagerException('Запрос не содерджит callable');
                 }
                 $result = $closure($this);
                 $response = new Response($result);
             } catch (\Exception $e) {
                 $this->logger->error('Exception при обработке запроса ' . $e->getMessage());
                 $response = new Response($e->getMessage(), Response::STATUS_ERROR);
             }
             if ($replayTo = $frame->getHeader('reply-to')) {
                 $body = $this->messageTransformer->encodeResponse($response);
                 $client->send($replayTo, $body);
             }
         });
     }, function (\Exception $e) {
         $this->logger->critical($e->getMessage());
     });
     $this->loop->run();
 }
 /**
  * Start server
  *
  * @throws RuntimeException
  */
 public function run()
 {
     try {
         $this->loop->addPeriodicTimer($this->timePeriod, $this->getPeriodicTimerCallback());
         //listening of the ports
         foreach ($this->listen as $port) {
             $socket = new Server($this->loop);
             //initialize socket
             $socket->on('connection', function (Connection $conn) {
                 $this->conns->attach($conn);
                 $conn->on('data', function ($data, $conn) {
                     //$request insteadof React\Http\Request
                     list($request, $body) = (new RequestHeaderParser())->parseRequest($data);
                     $this->conns->attach($conn, new LongPooling\ConnectionInfo($request, $body));
                 });
                 $conn->on('end', function ($conn) {
                     $this->conns->detach($conn);
                 });
             });
             $socket->listen($port);
         }
         $this->loop->run();
     } catch (Exception $e) {
         throw new RuntimeException("Server Run Exception", 301, $e);
     }
 }
Esempio n. 19
0
 /**
  * Start the event reactor and assume program flow control
  *
  * @param callable $onStart Optional callback to invoke immediately upon reactor start
  */
 public function run(callable $onStart = null)
 {
     if ($onStart) {
         $this->reactor->nextTick($onStart);
     }
     $this->reactor->run();
 }
Esempio n. 20
0
 /**
  * Start the transport
  */
 public function start($startLoop = true)
 {
     $this->transportProvider->startTransportProvider($this, $this->loop);
     if ($startLoop) {
         $this->loop->run();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function sendAsyncRequest(RequestInterface $request)
 {
     $requestStream = $this->buildReactRequest($request);
     $deferred = new Deferred();
     $requestStream->on('error', function (\Exception $error) use($deferred, $request) {
         $deferred->reject(new RequestException($error->getMessage(), $request, $error));
     });
     $requestStream->on('response', function (ReactResponse $response = null) use($deferred, $requestStream, $request) {
         $bodyStream = null;
         $response->on('data', function ($data) use(&$bodyStream) {
             if ($data instanceof StreamInterface) {
                 $bodyStream = $data;
             } else {
                 $bodyStream->write($data);
             }
         });
         $response->on('end', function (\Exception $error = null) use($deferred, $request, $response, &$bodyStream) {
             $bodyStream->rewind();
             $psr7Response = $this->messageFactory->createResponse($response->getCode(), $response->getReasonPhrase(), $response->getHeaders(), $bodyStream, $response->getVersion());
             if (null !== $error) {
                 $deferred->reject(new HttpException($error->getMessage(), $request, $psr7Response, $error));
             } else {
                 $deferred->resolve($psr7Response);
             }
         });
     });
     $requestStream->end((string) $request->getBody());
     $promise = new ReactPromiseAdapter($deferred->promise());
     $this->loop->run();
     return $promise;
 }
 /**
  * @param QueueMessage $message
  *
  * @return void
  */
 protected function publishMessage(QueueMessage $message)
 {
     $this->channelFactory->fanout($this->exchange, $this->channel)->then(function ($r) use($message) {
         /** @var Channel $channel */
         $channel = $r[0];
         return \React\Promise\all([$channel->publish(json_encode($this->serializer->serialize($message)), [], $this->exchange)]);
     }, function (Exception $exception) {
         $this->loop->stop();
         throw new AsyncMessagingException(sprintf('Could not publish message: %s on line %s in file %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()), 0, $exception);
     })->then(function () {
         $this->loop->stop();
     }, function (Exception $exception) {
         $this->loop->stop();
         var_dump(sprintf('Could not publish message: %s on line %s in file %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()));
     });
     $this->loop->run();
 }
Esempio n. 23
0
 private function assertRunFasterThan($maxInterval)
 {
     $start = microtime(true);
     $this->loop->run();
     $end = microtime(true);
     $interval = $end - $start;
     $this->assertLessThan($maxInterval, $interval);
 }
Esempio n. 24
0
 /**
  * Runs the application
  *
  * @return void
  */
 public function run()
 {
     if (!self::$defaultApplication) {
         self::$defaultApplication = $this;
     }
     $application = $this;
     if (OsDetector::isMacOS()) {
         $processName = './phpgui-i386-darwin';
         $processPath = __DIR__ . '/../lazarus/phpgui-i386-darwin.app/Contents/MacOS/';
     } elseif (OsDetector::isFreeBSD()) {
         $processName = './phpgui-x86_64-freebsd';
         $processPath = __DIR__ . '/../lazarus/';
     } elseif (OsDetector::isUnix()) {
         $processName = './phpgui-x86_64-linux';
         $processPath = __DIR__ . '/../lazarus/';
     } elseif (OsDetector::isWindows()) {
         $processName = '.\\phpgui-x86_64-win64';
         $processPath = __DIR__ . '\\..\\lazarus\\';
     } else {
         throw new RuntimeException('Operational System not identified by PHP-GUI.');
     }
     $this->process = $process = new Process($processName, $processPath);
     $this->process->on('exit', function () use($application) {
         $application->loop->stop();
     });
     $this->receiver = $receiver = new Receiver($this);
     $this->sender = $sender = new Sender($this, $receiver);
     $this->loop->addTimer(0.001, function ($timer) use($process, $application, $receiver) {
         $process->start($timer->getLoop());
         // We need to pause all default streams
         // The react/loop uses fread to read data from streams
         // On Windows, fread always is blocking
         // Stdin is paused, we use our own way to write on it
         $process->stdin->pause();
         // Stdout is paused, we use our own way to read it
         $process->stdout->pause();
         // Stderr is paused for avoiding fread
         $process->stderr->pause();
         $process->stdout->on('data', function ($data) use($receiver) {
             $receiver->onData($data);
         });
         $process->stderr->on('data', function ($data) {
             if (!empty($data)) {
                 Output::err($data);
             }
         });
         $application->running = true;
         // Bootstrap the application
         $application->fire('start');
     });
     $this->loop->addPeriodicTimer(0.001, function () use($application) {
         $application->sender->tick();
         if (@is_resource($application->process->stdout->stream)) {
             $application->receiver->tick();
         }
     });
     $this->loop->run();
 }
Esempio n. 25
0
 /**
  * Starts the request loop
  */
 public function start()
 {
     $this->prepareEventLoop();
     $this->setupServer();
     $this->startTime = new DateTime();
     $this->_isRunning = TRUE;
     $this->eventLoop->run();
     $this->_isRunning = FALSE;
 }
Esempio n. 26
0
File: Shell.php Progetto: fieg/shell
 /**
  * Starts shell
  */
 public function run()
 {
     if ($this->running) {
         return;
     }
     $shell = $this;
     $this->loop->addReadStream(STDIN, function ($n) use($shell) {
         $c = stream_get_contents($n, 1);
         $shell->read($c);
     });
     // allows control keys to work
     if (function_exists('readline_callback_handler_install')) {
         readline_callback_handler_install('', function () {
         });
     }
     $this->running = true;
     $this->loop->run();
 }
Esempio n. 27
0
 /**
  * Calls {@link eventLoop}'s run() method. Processes messages for at most $maxSeconds.
  *
  * @param float $maxSeconds
  */
 public function run($maxSeconds = null)
 {
     if ($maxSeconds !== null) {
         $this->stopTimer = $this->eventLoop->addTimer($maxSeconds, function () {
             $this->stop();
         });
     }
     $this->eventLoop->run();
 }
Esempio n. 28
0
 /**
  * Start the transport
  *
  * @param boolean $startLoop
  * @throws \Exception
  */
 public function start($startLoop = true)
 {
     if ($this->transportProvider === null) {
         throw new \Exception("You must add exactly one transport provider prior to starting");
     }
     $this->transportProvider->startTransportProvider($this, $this->loop);
     if ($startLoop) {
         $this->loop->run();
     }
 }
Esempio n. 29
0
 /**
  * Starts the processor server.
  *
  * @param OutputInterface $output
  * @param bool $verbose
  * @throws \React\Socket\ConnectionException
  */
 public function start(OutputInterface &$output, $verbose = false)
 {
     $this->output = $output;
     $this->verbose = $verbose;
     $this->loop = Factory::create();
     $this->socket = new Server($this->loop);
     $http = new \React\Http\Server($this->socket);
     $http->on('request', [$this, 'manageRequest']);
     $this->socket->listen($this->port, $this->host);
     $this->registerListeners();
     $this->loop->addPeriodicTimer($this->interval, [$this, 'manageQueue']);
     $this->loop->run();
 }
Esempio n. 30
0
 /**
  * Start router
  *
  * @param bool $runLoop
  * @throws \Exception
  */
 public function start($runLoop = true)
 {
     Logger::info($this, "Starting router");
     if ($this->loop === null) {
         throw new \Exception("Loop is null");
     }
     $this->started = true;
     $this->eventDispatcher->dispatch("router.start", new RouterStartEvent());
     if ($runLoop) {
         Logger::info($this, "Starting loop");
         $this->loop->run();
     }
 }