Skip to content

Commit 9b843c0

Browse files
committed
Merge remote-tracking branch 'origin/3.x' into feature-proto-payloads
# Conflicts: # composer.json
2 parents f185ea0 + 0bd1ef8 commit 9b843c0

File tree

6 files changed

+103
-42
lines changed

6 files changed

+103
-42
lines changed

.github/workflows/phpunit.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ on:
22
pull_request: null
33
push:
44
branches:
5-
- master
65
- '*.*'
76

87
name: phpunit
@@ -13,7 +12,5 @@ jobs:
1312
with:
1413
os: >-
1514
['ubuntu-latest']
16-
php: >-
17-
['8.1', '8.2']
1815
stability: >-
1916
['prefer-lowest', 'prefer-stable']

.github/workflows/psalm.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ on:
22
pull_request: null
33
push:
44
branches:
5-
- master
65
- '*.*'
76

87
name: static analysis
@@ -13,5 +12,3 @@ jobs:
1312
with:
1413
os: >-
1514
['ubuntu-latest']
16-
php: >-
17-
['8.1']

README.md

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
<p align="center">
2-
<img src="https://user-images.githubusercontent.com/796136/50286124-6f7f3780-046f-11e9-9f45-e8fedd4f786d.png" height="75px" alt="RoadRunner">
3-
</p>
1+
<a href="https://roadrunner.dev" target="_blank">
2+
<picture>
3+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/roadrunner-server/.github/assets/8040338/e6bde856-4ec6-4a52-bd5b-bfe78736c1ff">
4+
<img align="center" src="https://github.com/roadrunner-server/.github/assets/8040338/040fb694-1dd3-4865-9d29-8e0748c2c8b8">
5+
</picture>
6+
</a>
47
<p align="center">
58
<a href="https://packagist.org/packages/spiral/roadrunner"><img src="https://poser.pugx.org/spiral/roadrunner/version"></a>
69
<a href="https://pkg.go.dev/github.com/spiral/roadrunner?tab=doc"><img src="https://godoc.org/github.com/spiral/roadrunner?status.svg"></a>
@@ -19,40 +22,40 @@ with much greater performance and flexibility.
1922

2023
<p align="center">
2124
<a href="https://roadrunner.dev/"><b>Official Website</b></a> |
22-
<a href="https://roadrunner.dev/docs"><b>Documentation</b></a>
25+
<a href="https://docs.roadrunner.dev"><b>Documentation</b></a>
2326
</p>
2427

25-
Repository:
26-
--------
28+
29+
## Repository:
2730

2831
This repository contains the codebase PSR-7 PHP workers.
2932
Check [spiral/roadrunner](https://github.com/spiral/roadrunner) to get application server.
3033

31-
Installation:
32-
--------
34+
35+
## Installation:
3336

3437
To install application server and HTTP codebase:
3538

3639
```bash
37-
$ composer require spiral/roadrunner-http nyholm/psr7
40+
composer require spiral/roadrunner-http nyholm/psr7
3841
```
3942

4043
You can use the convenient installer to download the latest available compatible version of RoadRunner assembly:
4144

4245
```bash
43-
$ composer require spiral/roadrunner-cli --dev
46+
composer require spiral/roadrunner-cli --dev
4447
```
4548

4649
To download latest version of application server:
4750

4851
```bash
49-
$ vendor/bin/rr get
52+
vendor/bin/rr get
5053
```
5154

52-
> You can use any [PSR-17 compatible implementation](https://github.com/search?q=psr-17).
55+
> You can use any [PSR-17 compatible implementation](https://packagist.org/providers/psr/http-factory-implementation).
56+
5357

54-
Example:
55-
-------
58+
## Example:
5659

5760
To init abstract RoadRunner worker:
5861

@@ -88,9 +91,9 @@ while (true) {
8891
$request = $psr7->waitRequest();
8992
} catch (\Throwable $e) {
9093
// Although the PSR-17 specification clearly states that there can be
91-
// no exceptions when creating a request, however, some implementations
92-
// may violate this rule. Therefore, it is recommended to process the
93-
// incoming request for errors.
94+
// no exceptions when creating a request, however, some implementations
95+
// may violate this rule. Therefore, it is recommended to process the
96+
// incoming request for errors.
9497
//
9598
// Send "Bad Request" response.
9699
$psr7->respond(new Response(400));
@@ -99,38 +102,61 @@ while (true) {
99102

100103
try {
101104
// Here is where the call to your application code will be located.
102-
// For example:
103-
//
105+
// For example:
106+
//
104107
// $response = $app->send($request);
105108
//
106109
// Reply by the 200 OK response
107110
$psr7->respond(new Response(200, [], 'Hello RoadRunner!'));
108111
} catch (\Throwable $e) {
109112
// In case of any exceptions in the application code, you should handle
110-
// them and inform the client about the presence of a server error.
111-
//
113+
// them and inform the client about the presence of a server error.
114+
//
112115
// Reply by the 500 Internal Server Error response
113116
$psr7->respond(new Response(500, [], 'Something Went Wrong!'));
114-
115-
// Additionally, we can inform the RoadRunner that the processing
116-
// of the request failed.
117+
118+
// Additionally, we can inform the RoadRunner that the processing
119+
// of the request failed.
117120
$worker->error((string)$e);
118121
}
119122
}
120123
```
121124

122-
<a href="https://spiral.dev/">
123-
<img src="https://user-images.githubusercontent.com/773481/220979012-e67b74b5-3db1-41b7-bdb0-8a042587dedc.jpg" alt="try Spiral Framework" />
124-
</a>
125+
### Stream response
126+
127+
To send a response in a stream, set the `$chunkSize` property in `PSR7Worker`:
128+
129+
```php
130+
$psr7 = new PSR7Worker($worker, $factory, $factory, $factory);
131+
$psr7->chunkSize = 512 * 1024; // 512KB
132+
```
133+
134+
Now PSR7Worker will cut the response into chunks of 512KB and send them to the stream.
135+
136+
### Early hints
137+
138+
To send multiple responses you may use the `\Spiral\RoadRunner\Http\HttpWorker::respond()` method with
139+
the `endOfStream` parameter set to `false`. This will send the response to the client and allow you to send
140+
additional responses.
141+
142+
```php
143+
/** @var \Spiral\RoadRunner\Http\PSR7Worker $psr7 */
144+
$httpWorker = $psr7->getHttpWorker()
145+
->respond(103, header: ['Link' => ['</style.css>; rel=preload; as=style']], endOfStream: false);
146+
147+
// End of stream will be sent automatically after PSR7Worker::respond() call
148+
$psr7->respond(new Response(200, [], 'Hello RoadRunner!'));
149+
```
150+
151+
152+
[![try Spiral Framework](https://user-images.githubusercontent.com/773481/220979012-e67b74b5-3db1-41b7-bdb0-8a042587dedc.jpg)](https://spiral.dev/)
125153

126-
Testing:
127-
--------
154+
## Testing:
128155

129-
This codebase is automatically tested via host repository - [spiral/roadrunner](https://github.com/spiral/roadrunner).
156+
This codebase is automatically tested via host repository - [spiral/roadrunner](https://github.com/roadrunner-server/roadrunner).
130157

131158

132-
License:
133-
--------
159+
## License:
134160

135161
The MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained
136162
by [Spiral Scout](https://spiralscout.com).

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
],
3232
"homepage": "https://spiral.dev/",
3333
"support": {
34-
"docs": "https://roadrunner.dev/docs",
34+
"docs": "https://docs.roadrunner.dev",
3535
"issues": "https://github.com/roadrunner-server/roadrunner/issues",
3636
"forum": "https://forum.roadrunner.dev/",
3737
"chat": "https://discord.gg/V6EK4he"
@@ -42,16 +42,15 @@
4242
"psr/http-factory": "^1.0.1",
4343
"psr/http-message": "^1.0.1 || ^2.0",
4444
"spiral/roadrunner": "^2023.3",
45-
"spiral/roadrunner-worker": "^3.3.0"
45+
"spiral/roadrunner-worker": "^3.1.0"
4646
},
4747
"require-dev": {
4848
"buggregator/trap": "^1.0",
4949
"jetbrains/phpstorm-attributes": "^1.0",
5050
"nyholm/psr7": "^1.3",
5151
"phpunit/phpunit": "^10.0",
5252
"roadrunner-php/roadrunner-api-dto": "^1.4",
53-
"symfony/process": "^6.2",
54-
"symfony/var-dumper": "^6.3",
53+
"symfony/process": "^6.2 || ^7.0",
5554
"vimeo/psalm": "^5.9"
5655
},
5756
"autoload": {

src/PSR7Worker.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function getWorker(): WorkerInterface
5454
return $this->httpWorker->getWorker();
5555
}
5656

57+
public function getHttpWorker(): HttpWorker
58+
{
59+
return $this->httpWorker;
60+
}
61+
5762
/**
5863
* @throws \JsonException
5964
*/

tests/Unit/PSR7WorkerTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Spiral\RoadRunner\Tests\Http\Unit;
4+
5+
use Nyholm\Psr7\Factory\Psr17Factory;
6+
use PHPUnit\Framework\TestCase;
7+
use Spiral\RoadRunner\Http\HttpWorker;
8+
use Spiral\RoadRunner\Http\PSR7Worker;
9+
use Spiral\RoadRunner\Worker;
10+
11+
class PSR7WorkerTest extends TestCase
12+
{
13+
public function testHttpWorkerIsAvailable(): void
14+
{
15+
$psrFactory = new Psr17Factory();
16+
17+
$psrWorker = new PSR7Worker(
18+
Worker::create(),
19+
$psrFactory,
20+
$psrFactory,
21+
$psrFactory,
22+
);
23+
24+
self::assertInstanceOf(HttpWorker::class, $psrWorker->getHttpWorker());
25+
}
26+
27+
protected function tearDown(): void
28+
{
29+
// Clean all extra output buffers
30+
$level = \ob_get_level();
31+
while (--$level > 0) {
32+
\ob_end_clean();
33+
}
34+
35+
parent::tearDown(); // TODO: Change the autogenerated stub
36+
}
37+
}

0 commit comments

Comments
 (0)