Skip to content

Commit d061947

Browse files
authored
New major (v4) package version (#35)
### Added - Package "binary" file allows using next options: - `laravel-path` for Laravel application base path changing - `relay-dsn` for RR relay changing (you can set `tcp://localhost:6001`, `unix:///tmp/rpc.sock` and others; `pipes` is used by default) - `refresh-app` for application instance refreshing on each incoming HTTP request (instead `APP_REFRESH` env variable) - Possibility to use unix socket or TCP port as a relay to communicate with RoadRunner - `Spiral\RoadRunnerLaravel\WorkerOptionsInterface` that describes worker starting options - Feature tests (`phpunit`) that uses real RR server running ### Changed - Minimal required PHP version now is `7.4` - Dependency `spiral/roadrunner` (`~1.8`) changed with `spiral/roadrunner-worker` and `spiral/roadrunner-http` (`^2.0`) - RR worker instance binding for DI from `Spiral\RoadRunner\PSR7Client` to `Spiral\RoadRunner\Http\PSR7Worker` - `Spiral\RoadRunnerLaravel\WorkerInterface::start` accepts `Spiral\RoadRunnerLaravel\WorkerOptionsInterface` now ### Removed - RR config file (`.rr.yaml`) publishing using `artisan vendor:publish` command - Listener `Spiral\RoadRunnerLaravel\Listeners\ResetDbConnectionsListener`
1 parent 078c280 commit d061947

File tree

71 files changed

+1150
-1262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1150
-1262
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Bug report
33
about: Create a report to help us improve
44
labels: type:bug
55
assignees: tarampampam
6-
76
---
87

98
## Describe the bug
@@ -28,9 +27,9 @@ assignees: tarampampam
2827
2928
Key | Value
3029
----------------------- | ----
31-
PHP version | <!-- e.g. `7.2.6` -->
32-
Current package version | <!-- e.g. `3.6.0` -->
33-
RoadRunner version | <!-- e.g. `1.8.3` -->
30+
PHP version | <!-- e.g. `8.0.3` -->
31+
Current package version | <!-- e.g. `4.0.0` -->
32+
RoadRunner version | <!-- e.g. `2.0.1` -->
3433
Environment | <!-- e.g. `docker`, `local`, `aws` -->
3534

3635
### RoadRunner configuration file content

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Feature request
33
about: Suggest an idea for this package
44
labels: type:enhancement
55
assignees: tarampampam
6-
76
---
87

98
### Is your feature request related to a problem?

.github/ISSUE_TEMPLATE/question.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Question
33
about: Ask anything
44
labels: type:question
55
assignees: tarampampam
6-
76
---
87

98
> If you have any questions feel free to ask

.github/workflows/tests.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ on:
1616

1717
jobs: # Docs: <https://help.github.com/en/articles/workflow-syntax-for-github-actions>
1818
tests:
19-
name: PHP ${{ matrix.php }} (${{ matrix.setup }} setup)
19+
name: PHP ${{ matrix.php }}, RR ${{ matrix.rr }} (${{ matrix.setup }} setup)
2020
runs-on: ubuntu-20.04
2121
timeout-minutes: 10
2222
strategy:
2323
fail-fast: false
2424
matrix:
2525
setup: ['basic', 'lowest']
26-
php: ['7.3', '7.4', '8.0']
26+
php: ['7.4', '8.0']
27+
rr: ['2.0.1']
2728
include:
28-
- php: '7.3'
29+
- php: '7.4'
2930
setup: 'basic'
3031
coverage: 'true'
3132
- php: '8.0'
@@ -35,6 +36,9 @@ jobs: # Docs: <https://help.github.com/en/articles/workflow-syntax-for-github-ac
3536
- name: Check out code
3637
uses: actions/checkout@v2
3738

39+
- name: Install RoadRunner Binary
40+
run: docker run --rm -v "/:/rootfs:rw" --entrypoint "" spiralscout/roadrunner:${{ matrix.rr }} cp /usr/bin/rr /rootfs/usr/bin/rr
41+
3842
- name: Setup PHP, with composer and extensions
3943
uses: shivammathur/setup-php@v2 # Action page: <https://github.com/shivammathur/setup-php>
4044
with:

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].
66

7+
## UNRELEASED (v4 candidate)
8+
9+
### Added
10+
11+
- Package "binary" file allows using next options:
12+
- `laravel-path` for Laravel application base path changing
13+
- `relay-dsn` for RR relay changing (you can set `tcp://localhost:6001`, `unix:///tmp/rpc.sock` and others; `pipes` is used by default)
14+
- `refresh-app` for application instance refreshing on each incoming HTTP request (instead `APP_REFRESH` env variable)
15+
- Possibility to use unix socket or TCP port as a relay to communicate with RoadRunner
16+
- `Spiral\RoadRunnerLaravel\WorkerOptionsInterface` that describes worker starting options
17+
- Feature tests (`phpunit`) that uses real RR server running
18+
19+
### Changed
20+
21+
- Minimal required PHP version now is `7.4`
22+
- Dependency `spiral/roadrunner` (`~1.8`) changed with `spiral/roadrunner-worker` and `spiral/roadrunner-http` (`^2.0`)
23+
- RR worker instance binding for DI from `Spiral\RoadRunner\PSR7Client` to `Spiral\RoadRunner\Http\PSR7Worker`
24+
- `Spiral\RoadRunnerLaravel\WorkerInterface::start` accepts `Spiral\RoadRunnerLaravel\WorkerOptionsInterface` now
25+
26+
### Removed
27+
28+
- RR config file (`.rr.yaml`) publishing using `artisan vendor:publish` command
29+
- Listener `Spiral\RoadRunnerLaravel\Listeners\ResetDbConnectionsListener`
30+
731
## v3.7.0
832

933
### Added

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
# Image page: <https://hub.docker.com/_/php>
12
FROM php:8.0-alpine
23

34
ENV COMPOSER_HOME="/tmp/composer"
45

5-
COPY --from=composer:2.0.7 /usr/bin/composer /usr/bin/composer
6+
# Image page: <https://hub.docker.com/_/composer>
7+
COPY --from=composer:2.0.11 /usr/bin/composer /usr/bin/composer
8+
9+
# Image page: <https://hub.docker.com/r/spiralscout/roadrunner>
10+
COPY --from=spiralscout/roadrunner:2.0.1 /usr/bin/rr /usr/bin/rr
611

712
RUN set -x \
813
&& apk add --no-cache binutils git \
914
&& apk add --no-cache --virtual .build-deps autoconf pkgconf make g++ gcc 1>/dev/null \
1015
# install xdebug (for testing with code coverage), but do not enable it
11-
&& pecl install xdebug-3.0.0 1>/dev/null \
16+
&& pecl install xdebug-3.0.3 1>/dev/null \
17+
&& docker-php-ext-install sockets pcntl \
1218
&& apk del .build-deps \
1319
&& mkdir --parents --mode=777 /src ${COMPOSER_HOME}/cache/repo ${COMPOSER_HOME}/cache/files \
1420
&& ln -s /usr/bin/composer /usr/bin/c \

README.md

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,41 @@ Easy way for connecting [RoadRunner][roadrunner] and [Laravel][laravel] applicat
1717

1818
## Installation
1919

20-
Require this package with composer using next command:
20+
Make sure that [RR binary file][roadrunner-binary-releases] already installed on your system (or docker image). Require this package with composer using next command:
2121

2222
```shell script
23-
$ composer require spiral/roadrunner-laravel "^3.4"
23+
$ composer require spiral/roadrunner-laravel "^4.0"
2424
```
2525

2626
> Installed `composer` is required ([how to install composer][getcomposer]).
2727
28-
> You need to fix the major version of package.
29-
3028
After that you can "publish" package configuration file (`./config/roadrunner.php`) using next command:
3129

3230
```shell script
3331
$ php ./artisan vendor:publish --provider='Spiral\RoadRunnerLaravel\ServiceProvider' --tag=config
3432
```
3533

36-
And basic RoadRunner configuration file (`./.rr.yaml.dist`):
34+
**Important**: despite the fact that worker allows you to refresh application instance on each HTTP request _(if worker started with option `--refresh-app`, eg.: `php ./vendor/bin/rr-worker start --refresh-app`)_, we strongly recommend avoiding this for performance reasons. Large applications can be hard to integrate with RoadRunner _(you must decide which of service providers must be reloaded on each request, avoid "static optimization" in some cases)_, but it's worth it.
3735

38-
```shell script
39-
$ php ./artisan vendor:publish --provider='Spiral\RoadRunnerLaravel\ServiceProvider' --tag=rr-config
40-
```
36+
### Upgrading guide (`v3.x` &rarr; `v4.x`)
4137

42-
After that you can modify configuration files as you wish.
43-
44-
**Important**: despite the fact that worker allows you to refresh application instance on each HTTP request _(if environment variable `APP_REFRESH` set to `true`)_, we strongly recommend to avoid this for performance reasons. Large applications can be hard to integrate with RoadRunner _(you must decide which of service providers must be reloaded on each request, avoid "static optimization" in some cases)_, but it's worth it.
38+
- Update current package in your application:
39+
- `composer remove spiral/roadrunner-laravel`
40+
- `composer require spiral/roadrunner-laravel "^4.0"`
41+
- Update your `.rr.yaml` config (take a look for sample [here][roadrunner_config]) - a lot of options was changed
42+
- Optionally change relay to socket or TCP port:
43+
> ```yaml
44+
> server:
45+
> command: "php ./vendor/bin/rr-worker start --relay-dsn unix:///var/run/rr-rpc.sock"
46+
> relay: "unix:///var/run/rr-rpc.sock"
47+
> ```
48+
- Update RR binary file (using [`roadrunner-cli`][roadrunner-cli] or download from [binary releases][roadrunner-binary-releases] page) up to `v2.x`
49+
- Update RoadRunner starting (`rr serve ...`) flags - `-v` and `-d` must be not used anymore
50+
- In your application code replace `Spiral\RoadRunner\PSR7Client` with `Spiral\RoadRunner\Http\PSR7Worker`
4551
4652
## Usage
4753
48-
After package installation you can use provided "binary" file as RoadRunner worker: `./vendor/bin/rr-worker`. This worker allows you to interact with incoming requests and outcoming responses using [laravel events system][laravel_events]. Also events contains:
54+
After package installation you can use provided "binary" file as RoadRunner worker: `./vendor/bin/rr-worker`. This worker allows you to interact with incoming requests and outgoing responses using [laravel events system][laravel_events]. Event contains:
4955
5056
Event classname | Application object | HTTP server request | HTTP request | HTTP response | Exception
5157
---------------------------- | :----------------: | :-----------------: | :----------: | :-----------: | :-------:
@@ -57,48 +63,47 @@ Event classname | Application object | HTTP server request | HTTP r
5763
`AfterLoopStoppedEvent` | ✔ | | | |
5864
`LoopErrorOccurredEvent` | ✔ | ✔ | | | ✔
5965
60-
Simple `.rr.yaml` config example:
66+
Simple `.rr.yaml` config example ([full example can be found here][roadrunner_config]):
67+
68+
> For `windows` path must be full (eg.: `php vendor/spiral/roadrunner-laravel/bin/rr-worker start`)
6169
6270
```yaml
63-
env:
64-
#APP_REFRESH: true
71+
server:
72+
command: "php ./vendor/bin/rr-worker start --relay-dsn unix:///var/run/rr-rpc.sock"
73+
relay: "unix:///var/run/rr-rpc.sock"
6574
6675
http:
6776
address: 0.0.0.0:8080
68-
workers:
69-
command: 'php ./vendor/bin/rr-worker' # for windows: `php vendor/spiral/roadrunner-laravel/bin/rr-worker`
70-
pool:
71-
numWorkers: 4
72-
maxJobs: 64 # jobs limitation is important
73-
74-
static:
75-
dir: 'public'
77+
middleware: ["headers", "static", "gzip"]
78+
pool:
79+
max_jobs: 64 # feel free to change this
80+
supervisor:
81+
exec_ttl: 60s
82+
headers:
83+
response:
84+
X-Powered-By: "RoadRunner"
85+
static:
86+
dir: "public"
87+
forbid: [".php"]
7688
```
7789
90+
**Socket** or **TCP port** relay usage is strongly recommended for avoiding problems with `dd()`, `dump()`, `echo()` and other similar functions, that sends data to the IO pipes.
91+
7892
Roadrunner server starting:
7993
8094
```shell script
81-
$ rr -c ./.rr.yaml serve -d
95+
$ rr serve -c ./.rr.yaml
8296
```
8397
8498
### Listeners
8599
86-
This package provides event listeners for resetings application state without full application reload _(like cookies, HTTP request, application instance, service-providers and other)_. Some of them already declared in configuration file, but you can declare own without any limitations.
87-
88-
### Environment variables
89-
90-
You can use the following environment variables:
91-
92-
Variable name | Description
93-
----------------- | -----------
94-
`APP_FORCE_HTTPS` | _(declared in configuration file)_ Forces application HTTPS schema usage
95-
`APP_REFRESH` | Refresh application instance on every request
100+
This package provides event listeners for resetting application state without full application reload _(like cookies, HTTP request, application instance, service-providers and other)_. Some of them already declared in configuration file, but you can declare own without any limitations.
96101
97102
### Known issues
98103
99104
#### Controller constructors
100105
101-
You should avoid to use HTTP controller constructors _(created or resolved instances in constructor can be shared between different requests)_. Use dependencies resolving in controller **methods** instead.
106+
You should avoid to use HTTP controller constructors _(created or resolved instances in a constructor can be shared between different requests)_. Use dependencies resolving in a controller **methods** instead.
102107
103108
Bad:
104109
@@ -266,7 +271,7 @@ Changes log can be [found here][link_changes_log].
266271
[![Issues][badge_issues]][link_issues]
267272
[![Issues][badge_pulls]][link_pulls]
268273
269-
If you will find any package errors, please, [make an issue][link_create_issue] in current repository.
274+
If you find any package errors, please, [make an issue][link_create_issue] in a current repository.
270275
271276
## License
272277
@@ -294,6 +299,9 @@ MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maint
294299
[link_license]:https://github.com/spiral/roadrunner-laravel/blob/master/LICENSE
295300
[getcomposer]:https://getcomposer.org/download/
296301
[roadrunner]:https://github.com/spiral/roadrunner
302+
[roadrunner_config]:https://github.com/spiral/roadrunner-binary/blob/master/.rr.yaml
297303
[laravel]:https://laravel.com
298304
[laravel_events]:https://laravel.com/docs/events
305+
[roadrunner-cli]:https://github.com/spiral/roadrunner-cli
306+
[roadrunner-binary-releases]:https://github.com/spiral/roadrunner-binary/releases
299307
[#10]:https://github.com/spiral/roadrunner-laravel/issues/10

bin/rr-worker

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ foreach (['../../..', '../..', '..', 'vendor', '../vendor', '../../vendor'] as $
3131

3232
if ($loaded !== true) {
3333
\fwrite(\STDERR, 'Composer autoload file was not found. Try to install project dependencies' . PHP_EOL);
34-
exit(10);
34+
exit(1);
3535
}
3636

3737
/*
@@ -45,33 +45,33 @@ if ($loaded !== true) {
4545
|
4646
*/
4747

48+
/** @var string|null $base_path */
4849
$base_path = null;
4950

5051
foreach (['../../../..', '../../..', '../..', '..', '../vendor/laravel/laravel'] as $path) {
5152
if (\is_file(__DIR__ . '/' . $path . '/bootstrap/app.php')) {
52-
$base_path = \realpath(__DIR__ . '/' . $path);
53+
$base_path = (string) \realpath(__DIR__ . '/' . $path);
5354
break;
5455
}
5556
}
5657

57-
if (! \is_string($base_path)) {
58-
\fwrite(\STDERR, 'Cannot find application base path' . PHP_EOL);
59-
exit(11);
60-
}
61-
6258
/*
6359
|--------------------------------------------------------------------------
64-
| Create Worker Instance
60+
| Create And Run Console Application
6561
|--------------------------------------------------------------------------
62+
|
63+
| Symfony console component is a nice wrapper around worker CLI options.
64+
|
6665
*/
6766

68-
// @todo: Make possible to use another worker class
69-
$worker = new \Spiral\RoadRunnerLaravel\Worker($base_path);
67+
$app = new \Symfony\Component\Console\Application(
68+
'RoadRunner worker',
69+
\Composer\InstalledVersions::getPrettyVersion('spiral/roadrunner-laravel')
70+
);
7071

71-
/*
72-
|--------------------------------------------------------------------------
73-
| Start Worker Loop
74-
|--------------------------------------------------------------------------
75-
*/
72+
$app->add(new \Spiral\RoadRunnerLaravel\Console\Commands\StartCommand(
73+
new \Spiral\RoadRunnerLaravel\Worker(),
74+
$base_path
75+
));
7676

77-
$worker->start((bool) \getenv('APP_REFRESH'));
77+
$app->run();

composer.json

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^7.3 || ^8.0",
19-
"ext-mbstring": "*",
18+
"php": "^7.4 || ^8.0",
2019
"illuminate/contracts": "~6.0 || ~7.0 || ~8.0",
2120
"illuminate/support": "~6.0 || ~7.0 || ~8.0",
2221
"illuminate/http": "~6.0 || ~7.0 || ~8.0",
2322
"illuminate/routing": "~6.0 || ~7.0 || ~8.0",
24-
"spiral/roadrunner": "~1.8",
23+
"spiral/roadrunner-worker": "^2.0",
24+
"spiral/roadrunner-http": "^2.0",
2525
"symfony/psr-http-message-bridge": "^1.2 || ^2.0",
26-
"laminas/laminas-diactoros": "^2"
26+
"laminas/laminas-diactoros": "^2",
27+
"symfony/console": "^4.3.4 || ^5.0",
28+
"composer-runtime-api": "^2.0"
2729
},
2830
"require-dev": {
29-
"ext-pdo": "*",
30-
"ext-pdo_sqlite": "*",
31-
"ext-sqlite3": "*",
3231
"laravel/laravel": "~6.0 || ~7.0 || ~8.0",
3332
"mockery/mockery": "^1.3.2",
34-
"phpstan/phpstan": "~0.12.34",
35-
"phpunit/phpunit": "^8.0 || ^9.3"
33+
"phpstan/phpstan": "~0.12.80",
34+
"phpunit/phpunit": "^8.0 || ^9.3",
35+
"guzzlehttp/guzzle": "^6.3 || ~7.0"
3636
},
3737
"autoload": {
3838
"psr-4": {
@@ -67,11 +67,6 @@
6767
]
6868
}
6969
},
70-
"suggest": {
71-
"illuminate/redis": "Required for dropping redis connections",
72-
"illuminate/database": "Required for dropping database connections",
73-
"avto-dev/stacked-dumper-laravel": "Stacked variables dumper for Laravel-based application"
74-
},
7570
"support": {
7671
"issues": "https://github.com/spiral/roadrunner-laravel/issues",
7772
"source": "https://github.com/spiral/roadrunner-laravel"

config/roadrunner.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use Spiral\RoadRunnerLaravel\Listeners;
55

66
return [
7-
87
/*
98
|--------------------------------------------------------------------------
109
| Force HTTPS Schema Usage
@@ -87,7 +86,6 @@
8786

8887
Events\AfterLoopIterationEvent::class => [
8988
Listeners\ClearInstancesListener::class,
90-
// Listeners\ResetDbConnectionsListener::class,
9189
Listeners\RunGarbageCollectorListener::class,
9290
],
9391

0 commit comments

Comments
 (0)