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
2831This repository contains the codebase PSR-7 PHP workers.
2932Check [ spiral/roadrunner] ( https://github.com/spiral/roadrunner ) to get application server.
3033
31- Installation:
32- --------
34+
35+ ## Installation:
3336
3437To 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
4043You 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
4649To 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
5760To 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
135161The MIT License (MIT). Please see [ ` LICENSE ` ] ( ./LICENSE ) for more information. Maintained
136162by [ Spiral Scout] ( https://spiralscout.com ) .
0 commit comments