Skip to content

Commit 8a30b05

Browse files
Koldo Picazakpicaza
authored andcommitted
update readme
1 parent 2caa200 commit 8a30b05

File tree

2 files changed

+171
-3
lines changed

2 files changed

+171
-3
lines changed

README.md

Lines changed: 170 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ This framework is based on concepts and components of other open source software
1313
Install a project using [composer](https://getcomposer.org/download/) package manager:
1414

1515
````bash
16-
composer create-project antidot-fw/reactive-starter:dev-master dev
16+
composer create-project antidot-fw/reactive-starter dev
1717
mv dev/.* dev/* ./ && rmdir dev
18-
bin/console react-server:http
18+
php public/index.php
1919
````
2020

2121
Open your browser on port `8080`
2222

23+
## Config
24+
2325
### Development Mode
2426

2527
To run it in dev mode you can run `config:development-mode` command
@@ -51,3 +53,169 @@ bin/console
5153
````
5254

5355
![Default console tool](https://getting-started.antidotfw.io/images/default-console.jpg)
56+
57+
## Async Usage
58+
59+
It allows executing promises inside PSR-15 and PSR-7 Middlewares and request handlers
60+
61+
### PSR-15 Middleware
62+
63+
```php
64+
<?php
65+
declare(strict_types = 1);
66+
67+
namespace App;
68+
69+
use Antidot\React\PromiseResponse;
70+
use Psr\Http\Message\ResponseInterface;
71+
use Psr\Http\Message\ServerRequestInterface;
72+
use Psr\Http\Server\MiddlewareInterface;
73+
use Psr\Http\Server\RequestHandlerInterface;
74+
75+
class SomeMiddleware implements MiddlewareInterface
76+
{
77+
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
78+
{
79+
return new PromiseResponse(
80+
resolve($request)->then(static fn(ServerrequestInsterface $request) => $handler->handle($request))
81+
);
82+
}
83+
}
84+
```
85+
86+
### PSR-7 Request Handler
87+
88+
```php
89+
<?php
90+
declare(strict_types = 1);
91+
92+
namespace App;
93+
94+
use Antidot\React\PromiseResponse;
95+
use Psr\Http\Message\ResponseInterface;
96+
use Psr\Http\Message\ServerRequestInterface;
97+
use Psr\Http\Server\RequestHandlerInterface;
98+
99+
class SomeMiddleware implements RequestHandlerInterface
100+
{
101+
public function process(ServerRequestInterface $request): ResponseInterface
102+
{
103+
return resolve($request)->then(
104+
function(ServerrequestInterface $request): ResponseInterface {
105+
return new Response('Hello World!!!');
106+
}
107+
);;
108+
}
109+
}
110+
```
111+
112+
## Classic Usage
113+
114+
It allows executing classic PSR-15 middleware and request handler:
115+
116+
### PSR-15 Middleware
117+
118+
```php
119+
<?php
120+
declare(strict_types = 1);
121+
122+
namespace App;
123+
124+
use Psr\Http\Message\ResponseInterface;
125+
use Psr\Http\Message\ServerRequestInterface;
126+
use Psr\Http\Server\MiddlewareInterface;
127+
use Psr\Http\Server\RequestHandlerInterface;
128+
129+
class SomeMiddleware implements MiddlewareInterface
130+
{
131+
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
132+
{
133+
return $handler->handle($request);
134+
}
135+
}
136+
```
137+
138+
### PSR-7 Request Handler
139+
140+
```php
141+
<?php
142+
declare(strict_types = 1);
143+
144+
namespace App;
145+
146+
use Psr\Http\Message\ResponseInterface;
147+
use Psr\Http\Message\ServerRequestInterface;
148+
use Psr\Http\Server\RequestHandlerInterface;
149+
150+
class SomeMiddleware implements RequestHandlerInterface
151+
{
152+
public function process(ServerRequestInterface $request): ResponseInterface
153+
{
154+
return new Response('Hello World!!!');
155+
}
156+
}
157+
```
158+
159+
## Benchmark
160+
161+
Using apache ab:
162+
163+
```bash
164+
> ab -n 40000 -c 64 http://127.0.0.1:8080/
165+
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
166+
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
167+
Licensed to The Apache Software Foundation, http://www.apache.org/
168+
169+
Benchmarking 127.0.0.1 (be patient)
170+
171+
Server Software: ReactPHP/1
172+
Server Hostname: 127.0.0.1
173+
Server Port: 8080
174+
175+
Document Path: /
176+
Document Length: 96 bytes
177+
178+
Concurrency Level: 64
179+
Time taken for tests: 16.201 seconds
180+
Complete requests: 40000
181+
Failed requests: 0
182+
Total transferred: 8960000 bytes
183+
HTML transferred: 3840000 bytes
184+
Requests per second: 2468.93 [#/sec] (mean)
185+
Time per request: 25.922 [ms] (mean)
186+
Time per request: 0.405 [ms] (mean, across all concurrent requests)
187+
Transfer rate: 540.08 [Kbytes/sec] received
188+
189+
Connection Times (ms)
190+
min mean[+/-sd] median max
191+
Connect: 0 0 0.0 0 1
192+
Processing: 15 26 1.4 25 33
193+
Waiting: 15 26 1.4 25 33
194+
Total: 16 26 1.4 25 33
195+
196+
Percentage of the requests served within a certain time (ms)
197+
50% 25
198+
66% 25
199+
75% 26
200+
80% 26
201+
90% 27
202+
95% 29
203+
98% 31
204+
99% 32
205+
100% 33 (longest request)
206+
207+
```
208+
209+
using wrk:
210+
211+
```bash
212+
> wrk -t8 -c64 -d15s http://127.0.0.1:8080/ [95ba8e6]
213+
Running 15s test @ http://127.0.0.1:8080/
214+
8 threads and 64 connections
215+
Thread Stats Avg Stdev Max +/- Stdev
216+
Latency 26.14ms 1.44ms 34.63ms 92.76%
217+
Req/Sec 306.84 24.52 373.00 81.17%
218+
36670 requests in 15.04s, 8.50MB read
219+
Requests/sec: 2437.45
220+
Transfer/sec: 578.42KB
221+
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"cs-fix": "phpcbf src --colors",
6262
"inspect": "phpstan analyse src -l7 --ansi",
6363
"test": "phpunit --colors=always",
64-
"watch": "php-watcher bin/console --arguments react-server:http --delay 5 --ansi"
64+
"watch": "php-watcher public/index.php --arguments --delay 5 --ansi"
6565
},
6666
"config": {
6767
"sort-packages": true

0 commit comments

Comments
 (0)