PHP code example of spiral / roadrunner-bridge

1. Go to this page and download the library: Download spiral/roadrunner-bridge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spiral / roadrunner-bridge example snippets


use Spiral\RoadRunnerBridge\Bootloader as RoadRunnerBridge;

protected const LOAD = [
    RoadRunnerBridge\HttpBootloader::class, // Optional, if it needs to work with http plugin
    RoadRunnerBridge\QueueBootloader::class, // Optional, if it needs to work with jobs plugin
    RoadRunnerBridge\CacheBootloader::class, // Optional, if it needs to work with KV plugin
    RoadRunnerBridge\GRPCBootloader::class, // Optional, if it needs to work with GRPC plugin
    RoadRunnerBridge\CentrifugoBootloader::class, // Optional, if it needs to work with centrifugo server
    RoadRunnerBridge\TcpBootloader::class, // Optional, if it needs to work with TCP plugin
    RoadRunnerBridge\MetricsBootloader::class, // Optional, if it needs to work with metrics plugin
    RoadRunnerBridge\LoggerBootloader::class, // Optional, if it needs to work with app-logger plugin
    RoadRunnerBridge\LockBootloader::class, // Optional, if it needs to work with lock plugin
    RoadRunnerBridge\ScaffolderBootloader::class, // Optional, to generate Centrifugo handlers and TCP services via Scaffolder
    RoadRunnerBridge\CommandBootloader::class,
    // ...
];

use Spiral\RoadRunnerBridge\Bootloader as RoadRunnerBridge;

protected const LOAD = [
    // ...
    RoadRunnerBridge\TcpBootloader::class,
    // ...
];



declare(strict_types=1);

return [
    /**
     * Services for each server.
     */
    'services' => [
        'smtp' => SomeService::class,
        'monolog' => OtherService::class
    ],

    /**
     * Interceptors, this section is optional.
     * @see https://spiral.dev/docs/cookbook-domain-core/2.8/en#core-interceptors
     */
    'interceptors' => [
        // several interceptors
        'smtp' => [
            SomeInterceptor::class,
            OtherInterceptor::class
        ],
        'monolog' => SomeInterceptor::class // one interceptor
    ],

    'debug' => env('TCP_DEBUG', false)
];



declare(strict_types=1);

namespace App\Tcp\Service;

use Spiral\RoadRunner\Tcp\Request;
use Spiral\RoadRunnerBridge\Tcp\Response\RespondMessage;
use Spiral\RoadRunnerBridge\Tcp\Response\ResponseInterface;
use Spiral\RoadRunnerBridge\Tcp\Service\ServiceInterface;

class TestService implements ServiceInterface
{
    public function handle(Request $request): ResponseInterface
    {
        // some logic

        return new RespondMessage('some message', true);
    }
}
bash
php app.php create:tcp-service Test