bckp/roadrunner

Nette 框架集成到 RoadRunner

v1.0.0-RC3 2023-12-04 20:14 UTC

This package is auto-updated.

Last update: 2024-09-04 21:49:17 UTC


README

build Coverage Status Downloads this Month Latest stable Coverage Status License

RoadRunner 集成到 Nette 框架中

安装

安装 Bckp/Roadrunner 的最佳方式是使用 Composer

$ composer require bckp/roadrunner

然后,您需要更新您的应用程序的小型更新。

配置应用程序

创建新的 RR 配置,在我们的例子中是 roadrunner.neon

extensions:
    roadrunner: Bckp\RoadRunner\DI\Extension

roadrunner:
    showExceptions: %debugMode%

然后我们需要更新我们的引导程序,因为 RR 扩展仍然是很大的 WIP,建议不要启用调试模式。所以,在当前的 Bootstrap 中,我们创建了一个新的静态方法来引导到 RR 插件

public static function bootRR(string $appDir): Configurator
{
    $configurator = new Configurator;

	$configurator->setTimeZone('Europe/Prague');
	$configurator->setTempDirectory($appDir . '/temp');

	$configurator->createRobotLoader()
		->addDirectory(__DIR__)
		->register();

	$configurator->addConfig($appDir . '/config/common.neon');
	$configurator->addConfig($appDir . '/config/services.neon');
	$configurator->addConfig($appDir . '/config/local.neon');
	$configurator->addConfig($appDir . '/config/roadrunner.neon');

	return $configurator;
}

最后,我们需要我们的入口点,它将由 RoadRunner 运行,我们称此脚本为 roadrunner.php

<?php
declare(strict_types=1);

use Bckp\RoadRunner\RoadRunner;
use App\Bootstrap;

define('ROOT_DIR', dirname(__DIR__));
require ROOT_DIR . '/vendor/autoload.php';

/** @psalm-suppress PossiblyNullReference */
Bootstrap::bootRR(ROOT_DIR)
		 ->createContainer()
		 ->getByType(RoadRunner::class)
		 ->run();

和 shell 对应版本(我们使用它来重定向错误消息)

#!/usr/bin/env sh
exec php /app-path/app/roadrunner.php 2>&3

现在我们可以运行 RoadRunner 并使用我们的应用程序,只需简单运行它即可

server:
    command: "sh /app-path/app/roadrunner.sh -d opcache.enable_cli=1"
    relay: "pipes"