Skip to content

Commit 1b8a236

Browse files
authored
Merge pull request #145 from roadrunner-php/misc
Maintenance
2 parents ed3be1b + 23ca5a0 commit 1b8a236

File tree

8 files changed

+241
-194
lines changed

8 files changed

+241
-194
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ indent_style = space
88
indent_size = 4
99
trim_trailing_whitespace = true
1010

11-
[*.{yml, yaml, sh, conf, neon*}]
11+
[*.{yml,yaml,sh,conf,neon*}]
1212
indent_size = 2
1313

1414
[Makefile]

.gitattributes

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
* text=auto
22

3-
/.github export-ignore
3+
/.* export-ignore
44
/tests export-ignore
55
/[Dd]ocker* export-ignore
6-
/.* export-ignore
7-
/phpunit.xml* export-ignore
6+
/*.xml export-ignore
7+
/*.xml.dist export-ignore
88
/phpstan.* export-ignore
99
/Makefile export-ignore
10+
/rector.php export-ignore

.github/workflows/cs-fix.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
on:
2+
push:
3+
branches:
4+
- '*'
5+
6+
name: Fix Code Style
7+
8+
jobs:
9+
cs-fix:
10+
permissions:
11+
contents: write
12+
uses: spiral/gh-actions/.github/workflows/cs-fix.yml@master

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
->include(__DIR__ . '/config')
1111
->include(__DIR__ . '/tests')
1212
->include(__DIR__ . '/rector.php')
13+
->allowRisky(false)
1314
->build();

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test: ## Execute php tests and linters
2929
docker-compose run $(RUN_APP_ARGS) app composer test
3030

3131
test-cover: ## Execute php tests with coverage
32-
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"'
32+
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"'
3333

3434
shell: ## Start shell into container with php
3535
docker-compose run $(RUN_APP_ARGS) app sh

README.md

Lines changed: 108 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,56 @@ Easy way for connecting [RoadRunner][roadrunner] and [Laravel][laravel] applicat
1212

1313
## Why Use This Package?
1414

15-
Laravel provides the [Octane](https://laravel.com/docs/12.x/octane) package which partially supports RoadRunner as an
16-
application server, but RoadRunner offers much more than just HTTP capabilities. It also includes Jobs, Temporal, gRPC,
17-
and other plugins.
15+
This package provides complete Laravel integration with RoadRunner, offering:
16+
17+
- Support for HTTP and other RoadRunner plugins like gRPC, Queue, KeyValue, and more.
18+
- [Temporal](https://temporal.io/) integration
19+
- Full RoadRunner configuration control
1820

1921
![RoadRunner](https://github.com/user-attachments/assets/609d2e29-b6af-478b-b350-1d27b77ed6fb)
2022

21-
> **Note:** There is an article that explains all the RoadRunner
22-
> plugins: https://butschster.medium.com/roadrunner-an-underrated-powerhouse-for-php-applications-46410b0abc
23+
> [!TIP]
24+
> [There is an article][rr-plugins-article] that explains all the RoadRunner plugins.
2325
24-
The main limitation of Octane is that it has a built-in worker only for the HTTP plugin and doesn't provide the ability
25-
to create additional workers for other RoadRunner plugins, restricting its use to just the HTTP plugin.
26+
## Table of Contents
2627

27-
Our **Laravel Bridge** solves this problem by taking a different approach:
28+
- [Get Started](#get-started)
29+
- [Installation](#installation)
30+
- [Configuration](#configuration)
31+
- [Starting the Server](#starting-the-server)
32+
- [How It Works](#how-it-works)
33+
- [Supported Plugins](#supported-plugins)
34+
- [HTTP Plugin](#http-plugin)
35+
- [Jobs (Queue) Plugin](#jobs-queue-plugin)
36+
- [gRPC Plugin](#grpc-plugin)
37+
- [Temporal](#temporal)
38+
- [Custom Workers](#custom-workers)
39+
- [Support](#support)
40+
- [License](#license)
2841

29-
1. We include `laravel/octane` in our package and reuse its **SDK** for clearing the state of Laravel applications
30-
2. We add support for running and configuring multiple workers for different RoadRunner plugins
31-
3. By reusing Octane's functionality for state clearing, we automatically support all third-party packages that are
32-
compatible with Octane
42+
## Get Started
3343

34-
**This way, you get the best of both worlds:** Octane's state management and RoadRunner's full plugin ecosystem.
44+
### Installation
3545

36-
## Installation
46+
First, install the Laravel Bridge package via Composer:
3747

38-
```shell script
48+
```shell
3949
composer require roadrunner-php/laravel-bridge
4050
```
4151

42-
After that you can "publish" package configuration file (`./config/roadrunner.php`) using next command:
52+
Publish the configuration file:
4353

44-
```shell script
54+
```shell
4555
php artisan vendor:publish --provider='Spiral\RoadRunnerLaravel\ServiceProvider' --tag=config
4656
```
4757

48-
## Usage
49-
50-
After package installation, you can download and install [RoadRunner][roadrunner] binary
51-
using [DLoad][dload] package:
58+
Download and install RoadRunner binary using DLoad:
5259

53-
```bash
60+
```shell
5461
./vendor/bin/dload get rr
5562
```
5663

57-
### Basic Configuration (.rr.yaml)
64+
### Configuration
5865

5966
Create a `.rr.yaml` configuration file in your project root:
6067

@@ -65,7 +72,6 @@ rpc:
6572

6673
server:
6774
command: 'php vendor/bin/rr-worker start'
68-
relay: pipes
6975

7076
http:
7177
address: 0.0.0.0:8080
@@ -82,49 +88,30 @@ http:
8288
forbid: [ ".php" ]
8389
```
8490
85-
## RoadRunner Worker Configuration
86-
87-
You can configure workers in `config/roadrunner.php` file in the `workers` section:
88-
89-
```php
90-
use Spiral\RoadRunner\Environment\Mode;
91-
use Spiral\RoadRunnerLaravel\Grpc\GrpcWorker;
92-
use Spiral\RoadRunnerLaravel\Http\HttpWorker;
93-
use Spiral\RoadRunnerLaravel\Queue\QueueWorker;
94-
use Spiral\RoadRunnerLaravel\Temporal\TemporalWorker;
91+
### Starting the Server
9592
96-
return [
97-
// ... other configuration options ...
93+
Start the RoadRunner server with:
9894
99-
'workers' => [
100-
Mode::MODE_HTTP => HttpWorker::class,
101-
Mode::MODE_JOBS => QueueWorker::class,
102-
Mode::MODE_GRPC => GrpcWorker::class,
103-
Mode::MODE_TEMPORAL => TemporalWorker::class,
104-
],
105-
];
95+
```shell
96+
./rr serve
10697
```
10798

108-
As you can see, there are several predefined workers for HTTP, Jobs, gRPC, and Temporal. Feel free to replace any of
109-
them with your implementation if needed. Or create your own worker, for example,
110-
for [Centrifugo](https://docs.roadrunner.dev/docs/plugins/centrifuge), [TCP](https://docs.roadrunner.dev/docs/plugins/tcp)
111-
or any other plugin.
112-
11399
## How It Works
114100

115-
In the server section of the RoadRunner config, we specify the command to start our worker:
101+
RoadRunner creates a worker pool by executing the command specified in the server configuration:
116102

117103
```yaml
118104
server:
119105
command: 'php vendor/bin/rr-worker start'
120-
relay: pipes
121106
```
122107
123-
When RoadRunner server creates a worker pool for a specific plugin, it exposes an environment variable `RR_MODE` that
124-
indicates which plugin is being used. Our worker checks this variable to determine which Worker class should handle the
125-
request based on the configuration in `roadrunner.php`.
108+
When RoadRunner creates a worker pool for a specific plugin,
109+
it sets the `RR_MODE` environment variable to indicate which plugin is being used.
110+
The Laravel Bridge checks this variable to determine
111+
which Worker class should handle the request based on your configuration.
126112

127-
The selected worker starts listening for requests from the RoadRunner server and handles them using the Octane worker,
113+
The selected worker then listens for requests from the RoadRunner server
114+
and handles them using the [Octane][octane] worker,
128115
which clears the application state after each task (request, command, etc.).
129116

130117
## Supported Plugins
@@ -148,16 +135,17 @@ http:
148135
forbid: [ ".php" ]
149136
```
150137

151-
> **Note:** Read more about the HTTP plugin in
152-
> the [RoadRunner documentation][https://docs.roadrunner.dev/docs/http/http].
138+
> [!TIP]
139+
> Read more about the HTTP plugin in the [RoadRunner documentation][roadrunner-docs-http].
153140

154141
### Jobs (Queue) Plugin
155142

156-
The Queue plugin allows you to use RoadRunner as a queue driver for Laravel.
143+
The Queue plugin allows you to use RoadRunner as a queue driver for Laravel
144+
without additional services like Redis or a database.
157145

158146
#### Configuration
159147

160-
First, add the Queue Service Provider in your `config/app.php`:
148+
First, add the Queue Service Provider in `config/app.php`:
161149

162150
```php
163151
'providers' => [
@@ -166,7 +154,7 @@ First, add the Queue Service Provider in your `config/app.php`:
166154
],
167155
```
168156

169-
Then, configure a new connection in your `config/queue.php`:
157+
Then, configure a new connection in `config/queue.php`:
170158

171159
```php
172160
'connections' => [
@@ -192,17 +180,17 @@ jobs:
192180
config: { }
193181
```
194182

195-
> **Note:** Read more about the Jobs plugin in
196-
> the [RoadRunner documentation][https://docs.roadrunner.dev/docs/queues-and-jobs/overview-queues].
197-
198-
Don't forget to set the `QUEUE_CONNECTION` environment variable in your `.env` file:
183+
Set the `QUEUE_CONNECTION` environment variable in your `.env` file:
199184

200185
```dotenv
201186
QUEUE_CONNECTION=roadrunner
202187
```
203188

204189
That's it! You can now dispatch jobs to the RoadRunner queue without any additional services like Redis or Database.
205190

191+
> [!TIP]
192+
> Read more about the Jobs plugin in the [RoadRunner documentation][roadrunner-docs-jobs].
193+
206194
### gRPC Plugin
207195

208196
The gRPC plugin enables serving gRPC services with your Laravel application.
@@ -263,36 +251,54 @@ return [
263251
];
264252
```
265253

266-
Download Temporal binary for development purposes using the following command:
254+
Download Temporal binary for development:
267255

268256
```bash
269257
./vendor/bin/dload get temporal
270258
```
271259

272-
To start the Temporal server, you can use the following command:
260+
Start the Temporal dev server:
273261

274262
```bash
275263
./temporal server start-dev --log-level error --color always
276264
```
277265

278-
#### Useful links
266+
#### Useful Links
279267

280268
- [PHP SDK on GitHub](https://github.com/temporalio/sdk-php)
281269
- [PHP SDK docs](https://docs.temporal.io/develop/php/)
282270
- [Code samples](https://github.com/temporalio/samples-php)
283271
- [Taxi service sample](https://github.com/butschster/podlodka-taxi-service)
284272

285-
## Starting RoadRunner Server
273+
## Custom Workers
286274

287-
To start the RoadRunner server:
275+
The RoadRunner Laravel Bridge comes with several predefined workers for common plugins,
276+
but you can easily create your own custom workers for any RoadRunner plugin.
277+
This section explains how to create and register custom workers in your application.
288278

289-
```shell script
290-
./rr serve
279+
### Understanding Workers
280+
281+
Workers are responsible for handling requests from the RoadRunner server
282+
and processing them in your Laravel application.
283+
The predefined workers are configured in the `config/roadrunner.php` file:
284+
285+
```php
286+
return [
287+
// ... other configuration options ...
288+
289+
'workers' => [
290+
Mode::MODE_HTTP => HttpWorker::class,
291+
Mode::MODE_JOBS => QueueWorker::class,
292+
Mode::MODE_GRPC => GrpcWorker::class,
293+
Mode::MODE_TEMPORAL => TemporalWorker::class,
294+
],
295+
];
291296
```
292297

293-
## Custom Workers
298+
### Creating Custom Workers
294299

295-
You can create your own custom workers by implementing the `Spiral\RoadRunnerLaravel\WorkerInterface`:
300+
To create a custom worker, you need to implement the `Spiral\RoadRunnerLaravel\WorkerInterface`.
301+
This interface has a single method, `start()`, which is called when the worker is started by the RoadRunner server:
296302

297303
```php
298304
namespace App\Workers;
@@ -304,30 +310,46 @@ class CustomWorker implements WorkerInterface
304310
{
305311
public function start(WorkerOptionsInterface $options): void
306312
{
307-
// Your custom worker implementation
313+
// Your worker implementation goes here
314+
// This method should handle requests from the RoadRunner server
308315
}
309316
}
310317
```
311318

312-
Then register it in the `config/roadrunner.php`:
319+
### Registering Custom Workers
320+
321+
After creating your custom worker, you need to register it in the `config/roadrunner.php` file:
313322

314323
```php
315324
return [
325+
// ... other configuration options ...
326+
316327
'workers' => [
317-
'custom' => \App\Workers\CustomWorker::class,
328+
// Existing workers
329+
Mode::MODE_HTTP => HttpWorker::class,
330+
Mode::MODE_JOBS => QueueWorker::class,
331+
332+
// Your custom worker for a custom or built-in plugin
333+
'custom_plugin' => \App\Workers\CustomWorker::class,
318334
],
319335
];
320336
```
321337

338+
The key in the `workers` array should match the value of the `RR_MODE` environment variable
339+
set by the RoadRunner server for your plugin.
340+
322341
## Support
323342

324-
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!
343+
If you find this package helpful, please consider giving it a star on GitHub.
344+
Your support helps make the project more visible to other developers who might benefit from it!
325345

326346
[![Issues][badge_issues]][link_issues]
327347
[![Issues][badge_pulls]][link_pulls]
328348

329349
If you find any package errors, please, [make an issue][link_create_issue] in a current repository.
330350

351+
You can also [sponsor this project][link_sponsor] to help ensure its continued development and maintenance.
352+
331353
## License
332354

333355
MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information.
@@ -374,6 +396,8 @@ MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information.
374396

375397
[link_pulls]:https://github.com/roadrunner-php/laravel-bridge/pulls
376398

399+
[link_sponsor]:https://github.com/sponsors/roadrunner-server
400+
377401
[link_license]:https://github.com/roadrunner-php/laravel-bridge/blob/master/LICENSE
378402

379403
[getcomposer]:https://getcomposer.org/download/
@@ -389,3 +413,11 @@ MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information.
389413
[laravel_events]:https://laravel.com/docs/events
390414

391415
[roadrunner-binary-releases]:https://github.com/roadrunner-server/roadrunner/releases
416+
417+
[roadrunner-docs-jobs]:https://docs.roadrunner.dev/docs/queues-and-jobs/overview-queues
418+
419+
[roadrunner-docs-http]:https://docs.roadrunner.dev/docs/http/http
420+
421+
[octane]:https://laravel.com/docs/12.x/octane
422+
423+
[rr-plugins-article]:https://butschster.medium.com/roadrunner-an-underrated-powerhouse-for-php-applications-46410b0abc

0 commit comments

Comments
 (0)