From b5fedc0b869dad2503123daf5609084a4917a474 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 8 May 2025 15:39:47 +0400 Subject: [PATCH 1/7] Add CS fixer CI workflow --- .github/workflows/cs-fix.yml | 12 ++++++++++++ .php-cs-fixer.dist.php | 1 + 2 files changed, 13 insertions(+) create mode 100644 .github/workflows/cs-fix.yml diff --git a/.github/workflows/cs-fix.yml b/.github/workflows/cs-fix.yml new file mode 100644 index 0000000..0395b27 --- /dev/null +++ b/.github/workflows/cs-fix.yml @@ -0,0 +1,12 @@ +on: + push: + branches: + - '*' + +name: Fix Code Style + +jobs: + cs-fix: + permissions: + contents: write + uses: spiral/gh-actions/.github/workflows/cs-fix.yml@master diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 9fd31dc..4d3b491 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -10,4 +10,5 @@ ->include(__DIR__ . '/config') ->include(__DIR__ . '/tests') ->include(__DIR__ . '/rector.php') + ->allowRisky(false) ->build(); From 1d6b4202d879879b17442ad5b499e00b37361e9d Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 8 May 2025 16:02:56 +0400 Subject: [PATCH 2/7] Update metafiles --- .editorconfig | 2 +- .gitattributes | 7 +- Makefile | 2 +- composer.json | 194 +++++++++++++++++++++++------------------------ phpunit.xml.dist | 33 ++++---- 5 files changed, 120 insertions(+), 118 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0dd272d..7fbab54 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,7 +8,7 @@ indent_style = space indent_size = 4 trim_trailing_whitespace = true -[*.{yml, yaml, sh, conf, neon*}] +[*.{yml,yaml,sh,conf,neon*}] indent_size = 2 [Makefile] diff --git a/.gitattributes b/.gitattributes index b35bb1f..6cf3d8c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,10 @@ * text=auto -/.github export-ignore +/.* export-ignore /tests export-ignore /[Dd]ocker* export-ignore -/.* export-ignore -/phpunit.xml* export-ignore +/*.xml export-ignore +/*.xml.dist export-ignore /phpstan.* export-ignore /Makefile export-ignore +/rector.php export-ignore diff --git a/Makefile b/Makefile index d10e286..d38f564 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ test: ## Execute php tests and linters docker-compose run $(RUN_APP_ARGS) app composer test test-cover: ## Execute php tests with coverage - docker-compose run --rm --user "0:0" -e 'XDEBUG_MODE=coverage' app sh -c 'docker-php-ext-enable xdebug && su $(shell whoami) -s /bin/sh -c "composer phpunit-cover"' + docker-compose run --rm --user "0:0" -e 'XDEBUG_MODE=coverage' app sh -c 'docker-php-ext-enable xdebug && su $(shell whoami) -s /bin/sh -c "composer phpunit:cover"' shell: ## Start shell into container with php docker-compose run $(RUN_APP_ARGS) app sh diff --git a/composer.json b/composer.json index 61e412b..8dfce17 100644 --- a/composer.json +++ b/composer.json @@ -1,103 +1,103 @@ { - "name": "roadrunner-php/laravel-bridge", - "type": "library", - "description": "Laravel integration for RoadRunner with support for HTTP, Jobs, gRPC, and Temporal plugins - going beyond Octane's capabilities", - "keywords": [ - "laravel", - "bridge", - "roadrunner", - "temporal", - "grpc", - "queue", - "cache", - "http" - ], - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/roadrunner-server" - } - ], - "license": "MIT", - "authors": [ - { - "name": "butschster", - "homepage": "https://github.com/butschster" + "name": "roadrunner-php/laravel-bridge", + "type": "library", + "description": "Laravel integration for RoadRunner with support for HTTP, Jobs, gRPC, and Temporal plugins - going beyond Octane's capabilities", + "keywords": [ + "laravel", + "bridge", + "roadrunner", + "temporal", + "grpc", + "queue", + "cache", + "http" + ], + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/roadrunner-server" + } + ], + "license": "MIT", + "authors": [ + { + "name": "butschster", + "homepage": "https://github.com/butschster" + }, + { + "name": "roxblnfk", + "homepage": "https://github.com/roxblnfk" + }, + { + "name": "tarampampam", + "homepage": "https://github.com/tarampampam" + } + ], + "require": { + "php": "^8.2", + "spiral/roadrunner-kv": "^4.0", + "spiral/roadrunner-jobs": "^4.0", + "spiral/roadrunner-grpc": "^3.5", + "laravel/octane": "^2.9", + "spiral/roadrunner-http": "^3.0", + "spiral/roadrunner-worker": "^3.0", + "temporal/sdk": "^2.0", + "internal/dload": "^1.1" }, - { - "name": "roxblnfk", - "homepage": "https://github.com/roxblnfk" + "require-dev": { + "laravel/framework": "^12.0", + "spiral/code-style": "^2.2.2", + "rector/rector": "^2.0", + "guzzlehttp/guzzle": "^7.0", + "mockery/mockery": "^1.6", + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^10.0" }, - { - "name": "tarampampam", - "homepage": "https://github.com/tarampampam" - } - ], - "require": { - "php": "^8.2", - "spiral/roadrunner-kv": "^4.0", - "spiral/roadrunner-jobs": "^4.0", - "spiral/roadrunner-grpc": "^3.5", - "laravel/octane": "^2.9", - "spiral/roadrunner-http": "^3.0", - "spiral/roadrunner-worker": "^3.0", - "temporal/sdk": "^2.0", - "internal/dload": "^1.1" - }, - "require-dev": { - "laravel/framework": "^12.0", - "spiral/code-style": "^2.2.2", - "rector/rector": "^2.0", - "guzzlehttp/guzzle": "^7.0", - "mockery/mockery": "^1.6", - "phpstan/phpstan": "^2.1", - "phpunit/phpunit": "^10.0" - }, - "autoload": { - "psr-4": { - "Spiral\\RoadRunnerLaravel\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Spiral\\RoadRunnerLaravel\\Tests\\": "tests/" - } - }, - "bin": [ - "bin/rr-worker" - ], - "scripts": { - "get:rr": "dload get rr", - "get:temporal": "dload get temporal", - "get:protoc": "dload get protoc protoc-gen-php-grpc", - "cs-check": "vendor/bin/php-cs-fixer fix --dry-run", - "cs-fix": "vendor/bin/php-cs-fixer fix", - "refactor": "rector process --config=rector.php", - "refactor:ci": "rector process --config=rector.php --dry-run --ansi", - "phpunit": "@php ./vendor/bin/phpunit --no-coverage", - "phpunit-cover": "@php ./vendor/bin/phpunit", - "phpstan": "@php ./vendor/bin/phpstan analyze -c ./phpstan.neon.dist --no-progress --ansi", - "test": [ - "@phpstan", - "@phpunit" + "autoload": { + "psr-4": { + "Spiral\\RoadRunnerLaravel\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Spiral\\RoadRunnerLaravel\\Tests\\": "tests/" + } + }, + "bin": [ + "bin/rr-worker" ], - "test-cover": [ - "@phpstan", - "@phpunit-cover" - ] - }, - "extra": { - "laravel": { - "providers": [ - "Spiral\\RoadRunnerLaravel\\ServiceProvider", - "Spiral\\RoadRunnerLaravel\\Queue\\QueueServiceProvider", - "Spiral\\RoadRunnerLaravel\\Cache\\CacheServiceProvider", - "Spiral\\RoadRunnerLaravel\\Temporal\\TemporalServiceProvider" - ] + "scripts": { + "get:rr": "dload get rr", + "get:temporal": "dload get temporal", + "get:protoc": "dload get protoc protoc-gen-php-grpc", + "cs:check": "php-cs-fixer fix --dry-run", + "cs:fix": "php-cs-fixer fix", + "refactor": "rector process --config=rector.php", + "refactor:ci": "rector process --config=rector.php --dry-run --ansi", + "phpunit": "phpunit --no-coverage", + "phpunit-cover": "phpunit", + "phpstan": "phpstan analyze -c ./phpstan.neon.dist --no-progress --ansi", + "test": "phpunit --color=always --testdox", + "test:unit": "phpunit --color=always --testsuite=Unit", + "test:feat": "phpunit --color=always --testsuite=Feature", + "test-cover": [ + "phpstan", + "@putenv XDEBUG_MODE=coverage", + "phpunit --coverage-clover=runtime/phpunit/logs/clover.xml --color=always" + ] + }, + "extra": { + "laravel": { + "providers": [ + "Spiral\\RoadRunnerLaravel\\ServiceProvider", + "Spiral\\RoadRunnerLaravel\\Queue\\QueueServiceProvider", + "Spiral\\RoadRunnerLaravel\\Cache\\CacheServiceProvider", + "Spiral\\RoadRunnerLaravel\\Temporal\\TemporalServiceProvider" + ] + } + }, + "support": { + "issues": "https://github.com/roadrunner-php/laravel-bridge/issues", + "source": "https://github.com/roadrunner-php/laravel-bridge" } - }, - "support": { - "issues": "https://github.com/roadrunner-php/laravel-bridge/issues", - "source": "https://github.com/roadrunner-php/laravel-bridge" - } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1680c26..5cb43d4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,8 +2,12 @@ - + cacheResultFile="runtime/phpunit/result.cache" + colors="true" + stderr="true" + displayDetailsOnTestsThatTriggerWarnings="true" + displayDetailsOnTestsThatTriggerDeprecations="true" +> ./tests/Unit @@ -12,25 +16,22 @@ ./tests/Feature - - + - ./src + src - ./vendor - ./tests + tests + + - - - - + + + - - - - - + + + From 39d328ef1a186018181671cbe64f5cc5083fc6be Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 8 May 2025 16:44:01 +0400 Subject: [PATCH 3/7] First Readme fix iteration --- README.md | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f7b02b4..801a17e 100644 --- a/README.md +++ b/README.md @@ -12,26 +12,31 @@ Easy way for connecting [RoadRunner][roadrunner] and [Laravel][laravel] applicat ## Why Use This Package? -Laravel provides the [Octane](https://laravel.com/docs/12.x/octane) package which partially supports RoadRunner as an -application server, but RoadRunner offers much more than just HTTP capabilities. It also includes Jobs, Temporal, gRPC, -and other plugins. +This library offers the most complete integration of Laravel with RoadRunner. +You should definitely use this package if: -![RoadRunner](https://github.com/user-attachments/assets/609d2e29-b6af-478b-b350-1d27b77ed6fb) +- You want to use not only HTTP but also other RoadRunner plugins like gRPC, Queue, KV, and others. +- You want to use Temporal. +- You want to control RoadRunner configuration. -> **Note:** There is an article that explains all the RoadRunner -> plugins: https://butschster.medium.com/roadrunner-an-underrated-powerhouse-for-php-applications-46410b0abc +![RoadRunner](https://github.com/user-attachments/assets/609d2e29-b6af-478b-b350-1d27b77ed6fb) -The main limitation of Octane is that it has a built-in worker only for the HTTP plugin and doesn't provide the ability -to create additional workers for other RoadRunner plugins, restricting its use to just the HTTP plugin. +> [!TIP] +> [There is an article][rr-plugins-article] that explains all the RoadRunner plugins: -Our **Laravel Bridge** solves this problem by taking a different approach: -1. We include `laravel/octane` in our package and reuse its **SDK** for clearing the state of Laravel applications -2. We add support for running and configuring multiple workers for different RoadRunner plugins -3. By reusing Octane's functionality for state clearing, we automatically support all third-party packages that are - compatible with Octane +Table of content: -**This way, you get the best of both worlds:** Octane's state management and RoadRunner's full plugin ecosystem. +- [Installation](#installation) +- [Usage](#usage) +- [RoadRunner Worker Configuration](#roadrunner-worker-configuration) +- [How It Works](#how-it-works) +- [Supported Plugins](#supported-plugins) + - [HTTP Plugin](#http-plugin) + - [Jobs (Queue) Plugin](#jobs-queue-plugin) + - [gRPC Plugin](#grpc-plugin) + - [Temporal](#temporal) +- [Custom Workers] ## Installation @@ -65,7 +70,7 @@ rpc: server: command: 'php vendor/bin/rr-worker start' - relay: pipes + relay: pipes http: address: 0.0.0.0:8080 @@ -389,3 +394,7 @@ MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. [laravel_events]:https://laravel.com/docs/events [roadrunner-binary-releases]:https://github.com/roadrunner-server/roadrunner/releases + +[octane]https://laravel.com/docs/12.x/octane + +[rr-plugins-article]https://butschster.medium.com/roadrunner-an-underrated-powerhouse-for-php-applications-46410b0abc From d191d586f7c09eac9d6a9af277f9266dd6bb5186 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 8 May 2025 17:56:27 +0400 Subject: [PATCH 4/7] Second Readme fix iteration --- README.md | 126 ++++++++++++++++++++++++------------------------------ 1 file changed, 56 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index 801a17e..7fe36f6 100644 --- a/README.md +++ b/README.md @@ -22,44 +22,47 @@ You should definitely use this package if: ![RoadRunner](https://github.com/user-attachments/assets/609d2e29-b6af-478b-b350-1d27b77ed6fb) > [!TIP] -> [There is an article][rr-plugins-article] that explains all the RoadRunner plugins: +> [There is an article][rr-plugins-article] that explains all the RoadRunner plugins. +## Table of Contents -Table of content: - -- [Installation](#installation) -- [Usage](#usage) -- [RoadRunner Worker Configuration](#roadrunner-worker-configuration) +- [Get Started](#get-started) + - [Installation](#installation) + - [Configuration](#configuration) + - [Starting the Server](#starting-the-server) - [How It Works](#how-it-works) - [Supported Plugins](#supported-plugins) - [HTTP Plugin](#http-plugin) - [Jobs (Queue) Plugin](#jobs-queue-plugin) - [gRPC Plugin](#grpc-plugin) - [Temporal](#temporal) -- [Custom Workers] +- [Custom Workers](#custom-workers) +- [Support](#support) +- [License](#license) + +## Get Started + +### Installation -## Installation +First, install the Laravel Bridge package via Composer: -```shell script +```shell composer require roadrunner-php/laravel-bridge ``` -After that you can "publish" package configuration file (`./config/roadrunner.php`) using next command: +Publish the configuration file: -```shell script +```shell php artisan vendor:publish --provider='Spiral\RoadRunnerLaravel\ServiceProvider' --tag=config ``` -## Usage +Download and install RoadRunner binary using DLoad: -After package installation, you can download and install [RoadRunner][roadrunner] binary -using [DLoad][dload] package: - -```bash +```shell ./vendor/bin/dload get rr ``` -### Basic Configuration (.rr.yaml) +### Configuration Create a `.rr.yaml` configuration file in your project root: @@ -70,7 +73,6 @@ rpc: server: command: 'php vendor/bin/rr-worker start' - relay: pipes http: address: 0.0.0.0:8080 @@ -87,50 +89,27 @@ http: forbid: [ ".php" ] ``` -## RoadRunner Worker Configuration +### Starting the Server -You can configure workers in `config/roadrunner.php` file in the `workers` section: +Start the RoadRunner server with: -```php -use Spiral\RoadRunner\Environment\Mode; -use Spiral\RoadRunnerLaravel\Grpc\GrpcWorker; -use Spiral\RoadRunnerLaravel\Http\HttpWorker; -use Spiral\RoadRunnerLaravel\Queue\QueueWorker; -use Spiral\RoadRunnerLaravel\Temporal\TemporalWorker; - -return [ - // ... other configuration options ... - - 'workers' => [ - Mode::MODE_HTTP => HttpWorker::class, - Mode::MODE_JOBS => QueueWorker::class, - Mode::MODE_GRPC => GrpcWorker::class, - Mode::MODE_TEMPORAL => TemporalWorker::class, - ], -]; +```shell +./rr serve ``` -As you can see, there are several predefined workers for HTTP, Jobs, gRPC, and Temporal. Feel free to replace any of -them with your implementation if needed. Or create your own worker, for example, -for [Centrifugo](https://docs.roadrunner.dev/docs/plugins/centrifuge), [TCP](https://docs.roadrunner.dev/docs/plugins/tcp) -or any other plugin. - ## How It Works -In the server section of the RoadRunner config, we specify the command to start our worker: +RoadRunner creates a worker pool by executing the command specified in the server configuration: ```yaml server: command: 'php vendor/bin/rr-worker start' - relay: pipes ``` -When RoadRunner server creates a worker pool for a specific plugin, it exposes an environment variable `RR_MODE` that -indicates which plugin is being used. Our worker checks this variable to determine which Worker class should handle the -request based on the configuration in `roadrunner.php`. +When RoadRunner creates a worker pool for a specific plugin, it sets the `RR_MODE` environment variable to indicate which plugin is being used. +The Laravel Bridge checks this variable to determine which Worker class should handle the request based on your configuration. -The selected worker starts listening for requests from the RoadRunner server and handles them using the Octane worker, -which clears the application state after each task (request, command, etc.). +The selected worker then listens for requests from the RoadRunner server and handles them using the Octane worker, which clears the application state after each task (request, command, etc.). ## Supported Plugins @@ -153,16 +132,15 @@ http: forbid: [ ".php" ] ``` -> **Note:** Read more about the HTTP plugin in -> the [RoadRunner documentation][https://docs.roadrunner.dev/docs/http/http]. +> **Note:** Read more about the HTTP plugin in the [RoadRunner documentation](https://docs.roadrunner.dev/docs/http/http). ### Jobs (Queue) Plugin -The Queue plugin allows you to use RoadRunner as a queue driver for Laravel. +The Queue plugin allows you to use RoadRunner as a queue driver for Laravel without additional services like Redis or a database. #### Configuration -First, add the Queue Service Provider in your `config/app.php`: +First, add the Queue Service Provider in `config/app.php`: ```php 'providers' => [ @@ -171,7 +149,7 @@ First, add the Queue Service Provider in your `config/app.php`: ], ``` -Then, configure a new connection in your `config/queue.php`: +Then, configure a new connection in `config/queue.php`: ```php 'connections' => [ @@ -197,10 +175,7 @@ jobs: config: { } ``` -> **Note:** Read more about the Jobs plugin in -> the [RoadRunner documentation][https://docs.roadrunner.dev/docs/queues-and-jobs/overview-queues]. - -Don't forget to set the `QUEUE_CONNECTION` environment variable in your `.env` file: +Set the `QUEUE_CONNECTION` environment variable in your `.env` file: ```dotenv QUEUE_CONNECTION=roadrunner @@ -208,6 +183,9 @@ QUEUE_CONNECTION=roadrunner That's it! You can now dispatch jobs to the RoadRunner queue without any additional services like Redis or Database. +> [!TIP] +> Read more about the Jobs plugin in the [RoadRunner documentation](https://docs.roadrunner.dev/docs/queues-and-jobs/overview-queues). + ### gRPC Plugin The gRPC plugin enables serving gRPC services with your Laravel application. @@ -268,36 +246,44 @@ return [ ]; ``` -Download Temporal binary for development purposes using the following command: +Download Temporal binary for development: ```bash ./vendor/bin/dload get temporal ``` -To start the Temporal server, you can use the following command: +Start the Temporal dev server: ```bash ./temporal server start-dev --log-level error --color always ``` -#### Useful links +#### Useful Links - [PHP SDK on GitHub](https://github.com/temporalio/sdk-php) - [PHP SDK docs](https://docs.temporal.io/develop/php/) - [Code samples](https://github.com/temporalio/samples-php) - [Taxi service sample](https://github.com/butschster/podlodka-taxi-service) -## Starting RoadRunner Server +## Custom Workers -To start the RoadRunner server: +As you can see, there are several predefined workers for HTTP, Jobs, gRPC, and Temporal in `'workers'` section of `config/roadrunner.php`. +You can replace them with your own implementations if needed or create your own workers for other plugins, for example, +for [Centrifugo](https://docs.roadrunner.dev/docs/plugins/centrifuge), [TCP](https://docs.roadrunner.dev/docs/plugins/tcp) +or any other plugin. -```shell script -./rr serve +```php +return [ + 'workers' => [ + Mode::MODE_HTTP => HttpWorker::class, + Mode::MODE_JOBS => QueueWorker::class, + Mode::MODE_GRPC => GrpcWorker::class, + Mode::MODE_TEMPORAL => TemporalWorker::class, + ], +]; ``` -## Custom Workers - -You can create your own custom workers by implementing the `Spiral\RoadRunnerLaravel\WorkerInterface`: +To create your own custom workers start from implementing the `Spiral\RoadRunnerLaravel\WorkerInterface`: ```php namespace App\Workers; @@ -395,6 +381,6 @@ MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. [roadrunner-binary-releases]:https://github.com/roadrunner-server/roadrunner/releases -[octane]https://laravel.com/docs/12.x/octane +[octane]:https://laravel.com/docs/12.x/octane -[rr-plugins-article]https://butschster.medium.com/roadrunner-an-underrated-powerhouse-for-php-applications-46410b0abc +[rr-plugins-article]:https://butschster.medium.com/roadrunner-an-underrated-powerhouse-for-php-applications-46410b0abc From e4525f806b3080a82a1194a245f8014f73102530 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 8 May 2025 18:05:20 +0400 Subject: [PATCH 5/7] Third Readme fix iteration --- README.md | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7fe36f6..92c533c 100644 --- a/README.md +++ b/README.md @@ -267,13 +267,19 @@ Start the Temporal dev server: ## Custom Workers -As you can see, there are several predefined workers for HTTP, Jobs, gRPC, and Temporal in `'workers'` section of `config/roadrunner.php`. -You can replace them with your own implementations if needed or create your own workers for other plugins, for example, -for [Centrifugo](https://docs.roadrunner.dev/docs/plugins/centrifuge), [TCP](https://docs.roadrunner.dev/docs/plugins/tcp) -or any other plugin. +The RoadRunner Laravel Bridge comes with several predefined workers for common plugins, +but you can easily create your own custom workers for any RoadRunner plugin. +This section explains how to create and register custom workers in your application. + +### Understanding Workers + +Workers are responsible for handling requests from the RoadRunner server and processing them in your Laravel application. +The predefined workers are configured in the `config/roadrunner.php` file: ```php return [ + // ... other configuration options ... + 'workers' => [ Mode::MODE_HTTP => HttpWorker::class, Mode::MODE_JOBS => QueueWorker::class, @@ -283,7 +289,10 @@ return [ ]; ``` -To create your own custom workers start from implementing the `Spiral\RoadRunnerLaravel\WorkerInterface`: +### Creating Custom Workers + +To create a custom worker, you need to implement the `Spiral\RoadRunnerLaravel\WorkerInterface`. +This interface has a single method, `start()`, which is called when the worker is started by the RoadRunner server: ```php namespace App\Workers; @@ -300,12 +309,21 @@ class CustomWorker implements WorkerInterface } ``` -Then register it in the `config/roadrunner.php`: +### Registering Custom Workers + +After creating your custom worker, you need to register it in the `config/roadrunner.php` file: ```php return [ + // ... other configuration options ... + 'workers' => [ - 'custom' => \App\Workers\CustomWorker::class, + // Existing workers + Mode::MODE_HTTP => HttpWorker::class, + Mode::MODE_JOBS => QueueWorker::class, + + // Your custom worker for a custom or built-in plugin + 'custom_plugin' => \App\Workers\CustomWorker::class, ], ]; ``` From af87a044a9dcd758e1b4b2cfec9fb9be2d55330a Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 8 May 2025 18:22:46 +0400 Subject: [PATCH 6/7] Fourth Readme fix iteration --- README.md | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 92c533c..b549900 100644 --- a/README.md +++ b/README.md @@ -106,10 +106,14 @@ server: command: 'php vendor/bin/rr-worker start' ``` -When RoadRunner creates a worker pool for a specific plugin, it sets the `RR_MODE` environment variable to indicate which plugin is being used. -The Laravel Bridge checks this variable to determine which Worker class should handle the request based on your configuration. +When RoadRunner creates a worker pool for a specific plugin, +it sets the `RR_MODE` environment variable to indicate which plugin is being used. +The Laravel Bridge checks this variable to determine +which Worker class should handle the request based on your configuration. -The selected worker then listens for requests from the RoadRunner server and handles them using the Octane worker, which clears the application state after each task (request, command, etc.). +The selected worker then listens for requests from the RoadRunner server +and handles them using the [Octane][octane] worker, +which clears the application state after each task (request, command, etc.). ## Supported Plugins @@ -132,11 +136,13 @@ http: forbid: [ ".php" ] ``` -> **Note:** Read more about the HTTP plugin in the [RoadRunner documentation](https://docs.roadrunner.dev/docs/http/http). +> [!TIP] +> Read more about the HTTP plugin in the [RoadRunner documentation][roadrunner-docs-http]. ### Jobs (Queue) Plugin -The Queue plugin allows you to use RoadRunner as a queue driver for Laravel without additional services like Redis or a database. +The Queue plugin allows you to use RoadRunner as a queue driver for Laravel +without additional services like Redis or a database. #### Configuration @@ -184,7 +190,7 @@ QUEUE_CONNECTION=roadrunner That's it! You can now dispatch jobs to the RoadRunner queue without any additional services like Redis or Database. > [!TIP] -> Read more about the Jobs plugin in the [RoadRunner documentation](https://docs.roadrunner.dev/docs/queues-and-jobs/overview-queues). +> Read more about the Jobs plugin in the [RoadRunner documentation][roadrunner-docs-jobs]. ### gRPC Plugin @@ -273,7 +279,8 @@ This section explains how to create and register custom workers in your applicat ### Understanding Workers -Workers are responsible for handling requests from the RoadRunner server and processing them in your Laravel application. +Workers are responsible for handling requests from the RoadRunner server +and processing them in your Laravel application. The predefined workers are configured in the `config/roadrunner.php` file: ```php @@ -304,7 +311,8 @@ class CustomWorker implements WorkerInterface { public function start(WorkerOptionsInterface $options): void { - // Your custom worker implementation + // Your worker implementation goes here + // This method should handle requests from the RoadRunner server } } ``` @@ -328,15 +336,21 @@ return [ ]; ``` +The key in the `workers` array should match the value of the `RR_MODE` environment variable +set by the RoadRunner server for your plugin. + ## Support -If you find this package helpful, please consider giving it a star on GitHub. Your support helps make the project more visible to other developers who might benefit from it! +If you find this package helpful, please consider giving it a star on GitHub. +Your support helps make the project more visible to other developers who might benefit from it! [![Issues][badge_issues]][link_issues] [![Issues][badge_pulls]][link_pulls] If you find any package errors, please, [make an issue][link_create_issue] in a current repository. +You can also [sponsor this project][link_sponsor] to help ensure its continued development and maintenance. + ## License MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. @@ -383,6 +397,8 @@ MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. [link_pulls]:https://github.com/roadrunner-php/laravel-bridge/pulls +[link_sponsor]:https://github.com/sponsors/roadrunner-server + [link_license]:https://github.com/roadrunner-php/laravel-bridge/blob/master/LICENSE [getcomposer]:https://getcomposer.org/download/ @@ -399,6 +415,10 @@ MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. [roadrunner-binary-releases]:https://github.com/roadrunner-server/roadrunner/releases +[roadrunner-docs-jobs]:https://docs.roadrunner.dev/docs/queues-and-jobs/overview-queues + +[roadrunner-docs-http]:https://docs.roadrunner.dev/docs/http/http + [octane]:https://laravel.com/docs/12.x/octane [rr-plugins-article]:https://butschster.medium.com/roadrunner-an-underrated-powerhouse-for-php-applications-46410b0abc From 23ca5a04417a5d3ef422ad9ba0842a8a08cffa09 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 8 May 2025 18:44:07 +0400 Subject: [PATCH 7/7] Simplify docs --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b549900..b24337d 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,11 @@ Easy way for connecting [RoadRunner][roadrunner] and [Laravel][laravel] applicat ## Why Use This Package? -This library offers the most complete integration of Laravel with RoadRunner. -You should definitely use this package if: +This package provides complete Laravel integration with RoadRunner, offering: -- You want to use not only HTTP but also other RoadRunner plugins like gRPC, Queue, KV, and others. -- You want to use Temporal. -- You want to control RoadRunner configuration. +- Support for HTTP and other RoadRunner plugins like gRPC, Queue, KeyValue, and more. +- [Temporal](https://temporal.io/) integration +- Full RoadRunner configuration control ![RoadRunner](https://github.com/user-attachments/assets/609d2e29-b6af-478b-b350-1d27b77ed6fb)