Start router

@param bool $runLoop
@throws \Exception
353428
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();
        }
    }
621585
public static function run()
    {
        self::init();

        /*
         * Register routes.
         */
        call_user_func(function () {
            /** @noinspection PhpIncludeInspection */
            require self::$basePath . '/boot/routes.php';
            if (file_exists(self::$basePath . '/.manifest/plugins/routes.php')) {
                /** @noinspection PhpIncludeInspection */
                include self::$basePath . '/.manifest/plugins/routes.php';
            }
        });

        /*
         * Dispatch the HTTP request and send the response to the browser.
         */
        /** @var \Core\Services\Contracts\Router $router */
        $router   = DI::getInstance()->get('router');
        $request  = DI::getInstance()->get('request');
        $response = $router->dispatch($request);
        $response->send();
    }
667620
public function start()
    {
        $whoops  = new Run();
        $handler = new PrettyPageHandler();

        $handler->addResourcePath(__DIR__.'/Resources');
        $handler->setEditor('sublime');

        $whoops->pushHandler($handler);
        $whoops->register();

        $this->whoops = $whoops;
    }
994655
public function runServer()
    {
        $router = $this->drupalDir . '/.ht.router.php';
        if (!file_exists($router)) {
            $this->createFile(
                $router,
                file_get_contents(__DIR__ . '/.ht.router.php')
            );
        }

        $uri = parse_url($this->baseUrl);

        $this->serverProcess = ProcessBuilder::create()
            ->setPrefix('exec')
            ->add($this->phpBin)
            ->add('-S')
            ->add(sprintf('%s:%s', $uri['host'], $uri['port']))
            ->add($router)
            ->setWorkingDirectory($this->drupalDir)
            ->getProcess();

        $this->serverProcess->start();

        sleep(1);

        if (!$this->serverProcess->isRunning()) {
            throw new RuntimeException('PHP built-in server process terminated immediately');
        }

        // Also trap fatal errors to make sure running processes are terminated.
        register_shutdown_function([$this, 'stopServer']);
    }
350776
public function init()
    {
        $stream = @fopen($this->config['url'], 'a');
        if (!$stream) {
            throw new \RuntimeException(sprintf("Couldn't open resource '%s'", $this->config['url']));
        }

        $this->stream = $stream;

        if (!empty($this->config['lock']) && $this->config['lock'] === true && stream_supports_lock($this->stream)) {
            $this->useLocks = true;
        }
    }
24398
public function start()
    {
        try {
            $this->createClientSocket();
            $this->createWorkerJobSocket();
            $this->createWorkerReplySocket();
            $this->startWorkerPools();
            $this->loop->addPeriodicTimer(5, [$this, 'monitorChildProcesses']);
            $this->loop->addPeriodicTimer(10, [$this, 'monitorQueue']);
            $this->loop->run();
        } catch (ServerException $e) {
            $errorMsgPattern = 'Server error: %s (%s:%d)';
            $this->logger->emergency(sprintf($errorMsgPattern, $e->getMessage(), $e->getFile(), $e->getLine()));
        }
    }
293979
public void startup() {
        if (isRunning) return;

        Executors.getInstance().execute(new Runnable() {
            @Override
            public void run() {
                DispatcherHandler handler = new DispatcherHandler(AndServer.getContext());
                ComponentRegister register = new ComponentRegister(AndServer.getContext());
                register.register(handler, mGroup);

                mHttpServer = ServerBootstrap.bootstrap()
                    .setSocketConfig(SocketConfig.custom()
                        .setSoKeepAlive(true)
                        .setSoReuseAddress(true)
                        .setSoTimeout(mTimeout)
                        .setTcpNoDelay(true)
                        .build())
                    .setConnectionConfig(
                        ConnectionConfig.custom().setBufferSize(4 * 1024).setCharset(Charsets.UTF_8).build())
                    .setLocalAddress(mInetAddress)
                    .setListenerPort(mPort)
                    .setSslContext(mSSLContext)
                    .setSslSetupHandler(new SSLInitializerWrapper(mSSLInitializer))
                    .setServerInfo("AndServer/2.0.0")
                    .registerHandler("*", handler)
                    .setExceptionLogger(ExceptionLogger.NO_OP)
                    .create();
                try {
                    isRunning = true;
                    mHttpServer.start();

                    Executors.getInstance().post(new Runnable() {
                        @Override
                        public void run() {
                            if (mListener != null) mListener.onStarted();
                        }
                    });
                    Runtime.getRuntime().addShutdownHook(new Thread() {
                        @Override
                        public void run() {
                            mHttpServer.shutdown(3, TimeUnit.SECONDS);
                        }
                    });
                } catch (final Exception e) {
                    Executors.getInstance().post(new Runnable() {
                        @Override
                        public void run() {
                            if (mListener != null) mListener.onException(e);
                        }
                    });
                }
            }
        });
    }
1249290
def start(debug=False, host='127.0.0.1'):
    
    if debug:
        debug = True
    nago.protocols.httpserver.app.run(debug=debug, host=host)
1068781
public function forkAndRunService($bootstrap)
    {
        if (!is_callable($bootstrap)) {
            throw new \RuntimeException('$bootstrap must be callable.');
        }

        if ($this->service !== null) {
            // We already have a service.
            throw new \RuntimeException('Service already started.');
        }

        $serviceAddress = $this->getServiceAddress();
        $factory = $this->getSocketFactory();
        $logger = $this->getLogger();
        try {
            $this->service = PidTracker::fork(function() use ($bootstrap, $serviceAddress, $factory, $logger) {
                $socket = $factory->createReply(Factory::MODE_CONNECT, $serviceAddress);
                $service = new Service($socket);
                $service->setLogger($logger);
                call_user_func($bootstrap, $service);
                $service->run();
            });
            $this->getLogger()->info('Service (PID: '.$this->service->getPid().') started.');
        } catch (\RuntimeException $ex) {
            $this->getLogger()->error($ex->getMessage());
            throw $ex;
        }

        return $this;
    }
1054269
public function run()
    {
        $this->loop = Factory::create();

        $this->errorLogger = BufferingLogger::create();
        ErrorHandler::register(new ErrorHandler($this->errorLogger));

        $this->tryConnect();
        $this->loop->run();
    }
167300
private function runView(): void
    {
        $action = ($this->routeAction) ? $this->routeAction : 'index';

        \call_user_func([$this->view, $action]);
    }
344653
public function start()
    {
        if ($this->restart) {
            echo 'Restarting consumer.' . PHP_EOL;
            $this->restart = false;
        } else {
            echo 'Starting consumer.' . PHP_EOL;
        }

        $exchange = 'router';
        $queue    = 'msgs';

        $this->channel = $this->connection->channel();
        $this->channel->queue_declare($queue, false, true, false, false);
        $this->channel->exchange_declare($exchange, AMQPExchangeType::DIRECT, false, true, false);
        $this->channel->queue_bind($queue, $exchange);
        $this->channel->basic_consume(
            $queue,
            $this->consumerTag,
            false,
            false,
            false,
            false,
            [$this,'messageHandler'],
            null,
            ['x-cancel-on-ha-failover' => ['t', true]] // fail over to another node
        );

        echo 'Enter wait.' . PHP_EOL;
        while ($this->channel->is_consuming()) {
            $this->channel->wait();
        }
        echo 'Exit wait.' . PHP_EOL;
    }
208544
public function start() {
		$pid = @ pcntl_fork();
		if( $pid == -1 ) {
			throw new Exception( $this->getError( Thread::COULD_NOT_FORK ), Thread::COULD_NOT_FORK );
		}
		if( $pid ) {
			// parent
			$this->pid = $pid;
		}
		else {
			// child
			pcntl_signal( SIGTERM, array( $this, 'signalHandler' ) );
			$arguments = func_get_args();
			if ( !empty( $arguments ) ) {
				call_user_func_array( $this->runnable, $arguments );
			}
			else {
				call_user_func( $this->runnable );
			}

			exit( 0 );
		}
	}
275353
public function start()
    {
        $__scope = $this->_runHooks($this->_startHooks);
        extract($__scope);
        
        $this->_write($this->_socket, self::READY);
        
        /* Note the naming of the local variables due to shared scope with the user here */
        for (;;) {
            declare (ticks = 1);
            // don't exit on ctrl-c
            pcntl_signal(SIGINT, SIG_IGN, true);
            
            $this->_cancelled = false;
            
            $__input = $this->_transform($this->_read($this->_socket));
            
            if ($__input === null) {
                continue;
            }
            
            $__response = self::DONE;
            
            $this->_ppid = posix_getpid();
            $this->_pid  = pcntl_fork();
            
            if ($this->_pid < 0) {
                throw new \RuntimeException('Failed to fork child labourer');
            } elseif ($this->_pid > 0) {
                // kill the child on ctrl-c
                pcntl_signal(SIGINT, array(
                    $this,
                    'cancelOperation'
                ), true);
                pcntl_waitpid($this->_pid, $__status);
                
                if (!$this->_cancelled && $__status != (self::ABNORMAL_EXIT << 8)) {
                    $__response = self::EXITED;
                } else {
                    $this->_runHooks($this->_failureHooks);
                    $__response = self::FAILED;
                }
            } else {
                // if the user has installed a custom exception handler, install a new
                // one which calls it and then (if the custom handler didn't already exit)
                // exits with the correct status.
                // If not, leave the exception handler unset; we'll display
                // an uncaught exception error and carry on.
                $__oldexh = set_exception_handler(array(
                    $this,
                    'delegateExceptionHandler'
                ));
                if ($__oldexh && !$this->_userExceptionHandler) {
                    $this->_userExceptionHandler = $__oldexh; // save the old handler (once)
                } else {
                    restore_exception_handler();
                }
                
                // undo ctrl-c signal handling ready for user code execution
                pcntl_signal(SIGINT, SIG_DFL, true);
                $__pid = posix_getpid();
                
                $__result = eval($__input);
                
                if (posix_getpid() != $__pid) {
                    // whatever the user entered caused a forked child
                    // (totally valid, but we don't want that child to loop and wait for input)
                    exit(0);
                }
                
                if (preg_match('/\s*return\b/i', $__input)) {
                    fwrite(STDOUT, sprintf("%s\n", $this->_inspector->inspect($__result)));
                }
                $this->_expungeOldWorker();
            }
            
            $this->_write($this->_socket, $__response);
            
            if ($__response == self::EXITED) {
                exit(0);
            }
        }
    }
848589
public function start($arguments)
    {
        if (socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $this->sockets) === false) {
            throw  new \Exception(socket_strerror(socket_last_error()));
        }

        $pid = @pcntl_fork();
        if ($pid == -1) {
            $this->fatalError(Thread::COULD_NOT_FORK);
        }
        if ($pid) {
            // parent

            $this->_pid = $pid;
        } else {
            // child
            pcntl_signal(SIGTERM, array($this, 'handleSignal'));

            if (!empty($arguments)) {
                $results = call_user_func_array($this->runnable, $arguments);
            } else {
                $results = call_user_func($this->runnable);
            }

            $data = serialize($results);
            socket_write($this->sockets[0], str_pad($data, $this->message_length), $this->message_length);
            socket_close($this->sockets[0]);

            exit(0);
        }
    }
1329723
public function actionRunLoopDaemon() {
        $loop = Factory::create();

        $loop->addPeriodicTimer(1, function() {
            $this->runChunk();
        });

        $loop->run();
    }
641554
public function start() {

		if(!$this->started) {

			// only non-CLI environments are supposed to provide sessions

			if(PHP_SAPI !== 'cli') {
				
				// avoid starting an already started session

				if (
					(PHP_VERSION_ID >= 50400 && session_status() === PHP_SESSION_ACTIVE) ||
					(PHP_VERSION_ID < 50400 && session_id())
				) {
					throw new \RuntimeException('Failed to start the session: Session already started.');
				}

				// allow session only when no headers have been sent

				if (headers_sent($file, $line)) {
					throw new \RuntimeException(sprintf("Cannot start session. Headers have already been sent by file '%s' at line %d.", $file, $line));
				}

				if(!session_start()) {
					throw new \RuntimeException('Session start failed.');
				}
			}

			$this->loadSession();

		}
	}