Documentation/Launching the application/RoadRunner

RoadRunner

RoadRunner is a high-performance application server PHP, load balancer, and process manager.
RoadRunner is written in Go, is easy to install, and acts as a replacement for PHP-FPM. It supports xDebug and its alternatives, as well as profiling and monitoring tools like Datadog and New Relic. For more details, refer to the documentation of RoadRunner.

For the application to function correctly when launched using this technology, it must be developed with support for asynchronous mode.

In asynchronous mode, the loaded framework configurations, classes, initialized services, and cached data are reused, which significantly accelerates performance.
However, there are distinctive features, such as the need to monitor memory leaks more closely and eliminate blocking operations, and many familiar third-party libraries do not support asynchronous mode.
Storing state in the logical parts of the application becomes undesirable, especially if it is related to a request.

The framework's RollbackInterface is designed for state resetting after each asynchronous request.

To install the server resources for RoadRunner, use the official repository: github.com/roadrunner-server/roadrunner.

For RoadRunner, you will need to modify the file /public/index.php so that the HLEB2 framework operates in a loop.
Here’s a basic working example:

<?php
// File /public/index.php

use Spiral\RoadRunner;
use 
Nyholm\Psr7;

ini_set('display_errors''stderr');

include 
__DIR__ "/../vendor/autoload.php";

$worker RoadRunner\Worker::create();
$psrFactory = new Psr7\Factory\Psr17Factory();

$psr7 = new RoadRunner\Http\PSR7Worker($worker$psrFactory$psrFactory$psrFactory);

// Framework initialization outside the loop.
$framework = new Hleb\HlebAsyncBootstrap(__DIR__);

while (
$request $psr7->waitRequest()) {
    try {
        
// Getting an object with a response.
        
$response $framework->load($request)->getResponse();

        
// Convert the framework response to a handler format.
        
$psr7->respond(new Psr7\Response(...$response->getArgs()));

    } catch (
\Throwable $e) {
        
$psr7->respond(new Psr7\Response(500, [], 'Something Went Wrong!'));
        
$framework->errorLog($e);
    }
}

For RoadRunner, you also need to create a configuration file .rr.yaml in the root directory of the project (assuming the compiled server file named rr is located there).
An example of a minimal working configuration in .rr.yaml:

version: '3'
server:
    command: 'php ./public/index.php'
http:
    address: :8088
    middleware:
        - gzip
        - static
    static:
        dir: public
        forbid:
            - .php
            - .htaccess
    pool:
        num_workers: 6
        max_jobs: 64
        debug: false
        supervisor:
            max_worker_memory: 5
metrics:
    address: '127.0.0.1:2113'

In this configuration, RoadRunner limits the operation of a single process (worker) by the maximum allowable memory setting: http.pool.supervisor.max_worker_memory in megabytes. Therefore, if the process exceeds this limit, RoadRunner properly terminates it and proceeds to the next one.

The RoadRunner server is started with the console command:

$./rr serve

According to the configuration, the application will be accessible at the address:
http://localhost:8088

Server metrics in Prometheus format:
http://localhost:2113

Launch with Apache Swoole Server

Page translated: chatgpt 4-o
Back to top