|
10 | 10 |
|
11 | 11 | * PHP ^7.4|^8.0
|
12 | 12 | * Antidot Framework
|
| 13 | +* DriftPHP Server |
13 | 14 | * React Http
|
| 15 | +* React Promises |
14 | 16 | * Ramsey Uuid
|
15 | 17 |
|
16 | 18 | ## Description
|
@@ -74,78 +76,91 @@ $aggregator = new ConfigAggregator([
|
74 | 76 | return $aggregator->getMergedConfig();
|
75 | 77 | ```
|
76 | 78 |
|
77 |
| -The create your React Http server |
| 79 | +Default Config: |
78 | 80 |
|
79 | 81 | ```php
|
80 |
| -#!/usr/bin/env php |
81 | 82 | <?php
|
82 |
| -// public/index.php or everywhere you want to allocate your server |
83 | 83 |
|
84 |
| -declare(strict_types=1); |
| 84 | +$config = [ |
| 85 | + 'server' => [ |
| 86 | + 'host' => '0.0.0.0', |
| 87 | + 'port' => 5555, |
| 88 | + 'buffer_size' => 4096, |
| 89 | + 'max_concurrency' => 100, |
| 90 | + 'workers' => 1, |
| 91 | + 'static_folder' => 'public' |
| 92 | + ] |
| 93 | +] |
| 94 | + |
| 95 | +``` |
| 96 | + |
| 97 | +### Usage |
| 98 | + |
| 99 | +Two new commands will be added to the Antidot Framework CLI tool, to allow running the application on top of [Drift server](https://driftphp.io/#/?id=the-server) |
| 100 | + |
| 101 | +* `server:run`: Run Drift HTTP Server |
| 102 | +* `server:watch`: Watch Drift HTTP Server for development purposes |
| 103 | + |
| 104 | +```bash |
| 105 | +$ bin/console |
| 106 | +... |
| 107 | + server |
| 108 | + server:run Run Drift HTTP Server |
| 109 | + server:watch Watch Drift HTTP Server for development purposes |
85 | 110 |
|
86 |
| -use Antidot\Application\Http\Application; |
87 |
| -use Antidot\React\PromiseResponse; |
88 |
| -use Laminas\Diactoros\Response\HtmlResponse; |
89 |
| -use Psr\Http\Message\ServerRequestInterface; |
90 |
| -use Ramsey\Uuid\Uuid; |
91 |
| -use React\EventLoop\Factory; |
92 |
| -use React\Http\Middleware\LimitConcurrentRequestsMiddleware; |
93 |
| -use React\Http\Middleware\RequestBodyBufferMiddleware; |
94 |
| -use React\Http\Middleware\RequestBodyParserMiddleware; |
95 |
| -use React\Http\Middleware\StreamingRequestMiddleware; |
96 |
| -use React\Http\Server; |
97 |
| -use React\Socket\Server as Socket; |
98 |
| -use function React\Promise\resolve; |
99 |
| - |
100 |
| -require 'vendor/autoload.php'; |
101 |
| - |
102 |
| -call_user_func(static function () { |
103 |
| - $loop = Factory::create(); |
104 |
| - $container = require 'config/container.php'; |
105 |
| - $application = $container->get(Application::class); |
106 |
| - (require 'router/middleware.php')($application, $container); |
107 |
| - (require 'router/routes.php')($application, $container); |
108 |
| - |
109 |
| - $server = new Server( |
110 |
| - $loop, |
111 |
| - new StreamingRequestMiddleware(), |
112 |
| - new LimitConcurrentRequestsMiddleware(100), // 100 concurrent buffering handlers |
113 |
| - new RequestBodyBufferMiddleware(4 * 1024 * 1024), // 4 MiB |
114 |
| - new RequestBodyParserMiddleware(), |
115 |
| - static function (ServerRequestInterface $request) use ($application) { |
116 |
| - try { |
117 |
| - $response = new PromiseResponse( |
118 |
| - resolve($request) |
119 |
| - ->then(static fn ($request) => $request->withAttribute('request_id', Uuid::uuid4()->toString())) |
120 |
| - ->then(static fn ($request) => $application->handle($request)) |
121 |
| - ); |
122 |
| - } catch (Throwable $exception) { |
123 |
| - if (!empty($e = $exception->getPrevious())) { |
124 |
| - $exception = $e; |
125 |
| - } |
126 |
| - |
127 |
| - $response = new HtmlResponse( |
128 |
| - sprintf( |
129 |
| - '%s in file %s in line %s.', |
130 |
| - $exception->getMessage(), |
131 |
| - $exception->getFile(), |
132 |
| - $exception->getLine() |
133 |
| - ) |
134 |
| - ); |
135 |
| - } |
136 |
| - |
137 |
| - return resolve($response); |
138 |
| - } |
139 |
| - ); |
140 |
| - |
141 |
| - $server->on('error', function ($err) { |
142 |
| - dump($err); |
143 |
| - }); |
144 |
| - |
145 |
| - $socket = new Socket('0.0.0.0:8080', $loop); |
146 |
| - $server->listen($socket); |
147 |
| - |
148 |
| - $loop->run(); |
149 |
| -}); |
| 111 | +``` |
| 112 | + |
| 113 | +```bash |
| 114 | +$ bin/console server:run -h |
| 115 | +Description: |
| 116 | + Run Drift HTTP Server |
| 117 | + |
| 118 | +Usage: |
| 119 | + server:run [options] [--] [<path>] |
| 120 | + |
| 121 | +Arguments: |
| 122 | + path The server will start listening to this address [default: "0.0.0.0:5555"] |
| 123 | + |
| 124 | +Options: |
| 125 | + --static-folder[=STATIC-FOLDER] Static folder path [default: "public"] |
| 126 | + --no-static-folder Disable static folder |
| 127 | + --debug Enable debug |
| 128 | + --no-header Disable the header |
| 129 | + --no-cookies Disable cookies |
| 130 | + --no-file-uploads Disable file uploads |
| 131 | + --concurrent-requests[=CONCURRENT-REQUESTS] Limit of concurrent requests [default: 100] |
| 132 | + --request-body-buffer[=REQUEST-BODY-BUFFER] Limit of the buffer used for the Request body. In KiB. [default: 4096] |
| 133 | + --adapter[=ADAPTER] Server Adapter [default: "Antidot\React\DriftKernelAdapter"] |
| 134 | + --allowed-loop-stops[=ALLOWED-LOOP-STOPS] Number of allowed loop stops [default: 0] |
| 135 | + --workers[=WORKERS] Number of workers. Use -1 to get as many workers as physical thread available for your system. Maximum of 128 workers. Option disabled for watch command. [default: 16] |
| 136 | + -q, --quiet Do not output any message |
| 137 | + |
| 138 | +``` |
| 139 | + |
| 140 | +```bash |
| 141 | +$ bin/console server:watch -h |
| 142 | +Description: |
| 143 | + Watch Drift HTTP Server for development purposes |
| 144 | + |
| 145 | +Usage: |
| 146 | + server:watch [options] [--] [<path>] |
| 147 | + |
| 148 | +Arguments: |
| 149 | + path The server will start listening to this address [default: "0.0.0.0:5555"] |
| 150 | + |
| 151 | +Options: |
| 152 | + --static-folder[=STATIC-FOLDER] Static folder path [default: "public"] |
| 153 | + --no-static-folder Disable static folder |
| 154 | + --debug Enable debug |
| 155 | + --no-header Disable the header |
| 156 | + --no-cookies Disable cookies |
| 157 | + --no-file-uploads Disable file uploads |
| 158 | + --concurrent-requests[=CONCURRENT-REQUESTS] Limit of concurrent requests [default: 512] |
| 159 | + --request-body-buffer[=REQUEST-BODY-BUFFER] Limit of the buffer used for the Request body. In KiB. [default: 2048] |
| 160 | + --adapter[=ADAPTER] Server Adapter [default: "drift"] |
| 161 | + --allowed-loop-stops[=ALLOWED-LOOP-STOPS] Number of allowed loop stops [default: 0] |
| 162 | + --workers[=WORKERS] Number of workers. Use -1 to get as many workers as physical thread available for your system. Maximum of 128 workers. Option disabled for watch command. [default: 1] |
| 163 | + -q, --quiet Do not output any message |
150 | 164 |
|
151 | 165 | ```
|
| 166 | + |
0 commit comments