### Start RoadRunner in Development Mode Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Use this command to start the RoadRunner server with the development configuration file. Ensure you have copied the dev config file first. ```bash bin/rr serve -c .rr.dev.yaml ``` -------------------------------- ### Install Roadrunner Bundle Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Run this command to install the Roadrunner Bundle using Composer. ```bash composer require baldinof/roadrunner-bundle ``` -------------------------------- ### Dockerfile for RoadRunner Application Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md This Dockerfile sets up a PHP 8.1 Alpine environment, installs necessary dependencies, copies application code, installs Composer dependencies, downloads the RoadRunner binary, optimizes the autoloader, warms up the cache, and configures the container to run RoadRunner serve. ```Dockerfile # Dockerfile FROM php:8.1-alpine RUN apk add --no-cache linux-headers autoconf openssl-dev g++ make pcre-dev icu-dev zlib-dev libzip-dev && \ docker-php-ext-install bcmath intl opcache zip sockets && \ apk del --purge autoconf g++ make WORKDIR /usr/src/app COPY --from=composer:latest /usr/bin/composer /usr/bin/composer COPY composer.json composer.lock ./ RUN composer install --no-dev --no-scripts --prefer-dist --no-progress --no-interaction RUN ./vendor/bin/rr get-binary --location /usr/local/bin COPY . . ENV APP_ENV=prod RUN composer dump-autoload --optimize && \ composer check-platform-reqs && \ php bin/console cache:warmup EXPOSE 8080 CMD ["rr", "serve"] ``` -------------------------------- ### Get RoadRunner Binary Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Download the RoadRunner binary to your project's bin directory. ```bash vendor/bin/rr get --location bin/ ``` -------------------------------- ### Run RoadRunner Server Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Start the RoadRunner server. Use the -c flag to specify a configuration file, such as for watch mode. ```bash bin/rr serve ``` ```bash bin/rr serve -c .rr.dev.yaml ``` -------------------------------- ### Implement gRPC Service Interface Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Example of a PHP class implementing a gRPC service interface. Services are registered automatically. ```php setResult($in->getA() + $in->getB()); } } ``` -------------------------------- ### RoadRunner Bundle 2.x Configuration Example Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/UPGRADE-2-0.md This YAML configuration demonstrates the updated settings for kernel reboot strategies, allowed exceptions, and metrics. It is essential for users migrating to version 2.0. ```yaml baldinof_road_runner: # When the kernel should be rebooted. # See https://github.com/baldinof/roadrunner-bundle#kernel-reboots kernel_reboot: # if you want to use a fresh container on each request, use the `always` strategy strategy: on_exception # Exceptions you KNOW that do not put your app in an errored state allowed_exceptions: - Symfony\Component\HttpKernel\Exception\HttpExceptionInterface - Symfony\Component\Serializer\Exception\ExceptionInterface - Symfony\Contracts\HttpClient\Exception\ExceptionInterface # Allow to send prometheus metrics to the main RoadRunner process, # via a `Spiral\RoadRunner\MetricsInterface` service. # See https://github.com/baldinof/roadrunner-bundle#metrics metrics: enabled: false # collect: # my_counter: # type: counter # help: Some help # You can use middlewares to manipulate Symfony requests & responses. # See https://github.com/baldinof/roadrunner-bundle#middlewares # middlewares: # - App\Middleware\YourMiddleware ``` -------------------------------- ### Configure KV Caching Storage Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Example configuration for enabling KV caching within the RoadRunner bundle. ```yaml # config/packages/baldinof_road_runner.yaml baldinof_road_runner: kv: storages: - example ``` -------------------------------- ### Configure Cache Pool for RoadRunner KV Adapter Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Example of setting up a Symfony cache pool to use the RoadRunner KV adapter. ```yaml # config/packages/cache.yaml framework: cache: pools: cache.example: adapter: cache.adapter.roadrunner.kv_example ``` -------------------------------- ### Require RoadRunner Download Utility Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Install the RoadRunner CLI tool as a development dependency. ```bash composer require --dev spiral/roadrunner-cli ``` -------------------------------- ### Combined Kernel Reboot Strategies Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Combine multiple kernel reboot strategies for comprehensive worker management. This example combines 'on_exception', 'max_jobs', and 'memory' strategies with their respective configurations. ```yaml # config/packages/baldinof_road_runner.yaml baldinof_road_runner: kernel_reboot: strategy: [on_exception, max_jobs, memory] allowed_exceptions: - Symfony\Component\HttpKernel\Exception\HttpExceptionInterface - Symfony\Component\Serializer\Exception\ExceptionInterface - App\Exception\YourDomainException max_jobs: 1000 max_jobs_dispersion: 0.2 memory_threshold_mb: 256 ``` -------------------------------- ### Configure Metrics in Symfony Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Enable and configure metrics collection within your Symfony application's configuration file. This example sets up a 'user_login' counter. ```yaml # config/packages/baldinof_road_runner.yaml baldinof_road_runner: metrics: enabled: true collect: user_login: type: counter help: "Number of logged in user" ``` -------------------------------- ### Record Metrics in PHP Controller Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Inject the MetricsInterface into your controller to record custom application metrics. This example increments the 'user_login' counter. ```php use Spiral\RoadRunner\MetricsInterface; class YouController { public function index(MetricsInterface $metrics): Response { $metrics->add('user_login', 1); return new Response("..."); } } ``` -------------------------------- ### Configure Middlewares Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Add custom middlewares to the RoadRunner configuration. Middlewares are executed outside of Symfony's Kernel::handle() and are resolved at worker start. ```yaml baldinof_road_runner: middlewares: - App\Middleware\YourMiddleware ``` -------------------------------- ### Copy RoadRunner Default Configurations Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/UPGRADE-2-0.md Use this command to copy the default RoadRunner configurations to your project root when upgrading. ```bash cp vendor/baldinof/roadrunner-bundle/.rr.* . ``` -------------------------------- ### Kernel Reboot Strategies Configuration Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/CHANGELOG.md Configure kernel reboot behavior using strategies. 'always' is equivalent to the old `should_reboot_kernel: true`. 'on_exception' allows specifying exceptions that should not trigger a reboot. ```yaml kernel_reboot: strategy: always # equivalent to `should_reboot_kernel: true` ``` ```yaml kernel_reboot: strategy: on_exception # equivalent to `should_reboot_kernel: false` allowed_exceptions: - Symfony\Component\HttpKernel\Exception\HttpExceptionInterface ``` -------------------------------- ### Kernel Reboot Strategy: On Exception Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Configure the kernel to reboot on specific exceptions to ensure a fresh container. This prevents services from entering a non-recoverable state after an error. ```yaml # config/packages/baldinof_road_runner.yaml baldinof_road_runner: kernel_reboot: strategy: on_exception allowed_exceptions: - Symfony\Component\HttpKernel\Exception\HttpExceptionInterface - Symfony\Component\Serializer\Exception\ExceptionInterface - App\Exception\YourDomainException ``` -------------------------------- ### Configure RoadRunner for gRPC Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Basic server and gRPC configuration for RoadRunner. Ensure the application runtime is set correctly. ```yaml server: command: "php public/index.php" env: APP_RUNTIME: Baldinof\RoadRunnerBundle\Runtime\Runtime grpc: listen: "tcp://:9001" proto: - "calculator.proto" ``` -------------------------------- ### Configure RoadRunner KV Plugin Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Configuration for the RoadRunner KV plugin, specifying the driver and any necessary configuration. ```yaml # .rr.yaml rpc: listen: tcp://127.0.0.1:6001 kv: example: driver: memory config: { } ``` -------------------------------- ### Update RoadRunner Binary Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/UPGRADE-2-0.md Execute this command to download and update the RoadRunner binary to the latest version, which is necessary for version 2.0 compatibility. ```bash vendor/bin/rr get-binary --location bin ``` -------------------------------- ### Disable Default Integrations Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Configure the bundle to disable all default integrations by setting 'default_integrations' to false in your configuration. ```yaml baldinof_road_runner: default_integrations: false ``` -------------------------------- ### Kernel Reboot Strategy: Always Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Configure the kernel to always reboot on each request. This ensures a fresh container for every request, which can be useful for debugging or if services are stateful. ```yaml # config/packages/baldinof_road_runner.yaml baldinof_road_runner: kernel_reboot: strategy: always ``` -------------------------------- ### Configure RoadRunner Metrics Endpoint Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Configure the RoadRunner server to expose a Prometheus metrics endpoint. This involves setting the RPC listen address and the metrics address. ```yaml # .rr.yaml rpc: listen: "tcp:127.0.0.1:6001" metrics: address: "0.0.0.0:9180" # prometheus endpoint ``` -------------------------------- ### Kernel Reboot Strategy: Memory Threshold Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Configure the kernel to reboot when memory usage exceeds a specified threshold to prevent memory exhaustion. The threshold is defined in megabytes. ```yaml # config/packages/baldinof_road_runner.yaml baldinof_road_runner: kernel_reboot: strategy: memory memory_threshold_mb: 256 # memory threshold in megabytes (default: 128MB) ``` -------------------------------- ### Kernel Reboot Strategy: Max Jobs Source: https://github.com/baldinof/roadrunner-bundle/blob/3.x/README.md Configure the kernel to reboot after a maximum number of requests to prevent memory leaks in long-running applications. A dispersion value can be set to avoid simultaneous reboots across all workers. ```yaml # config/packages/baldinof_road_runner.yaml baldinof_road_runner: kernel_reboot: strategy: max_jobs max_jobs: 1000 # maximum number of request max_jobs_dispersion: 0.2 # dispersion 20% used to prevent simultaneous reboot of all active workers (kernel will rebooted between 800 and 1000 requests) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.