1 | <?php declare(strict_types=1); |
||
13 | class Configuration |
||
14 | { |
||
15 | /** |
||
16 | * Dispatch the connection to the workers in sequence. |
||
17 | * Recommended for stateless asynchronous server. |
||
18 | */ |
||
19 | public const DISPATCH_POLLING_MODE = 1; |
||
20 | |||
21 | /** |
||
22 | * Dispatch the connection to the worker according to the id number of connection. |
||
23 | * In this mode, the data from the same connection will be handled by the same worker process. |
||
24 | * Recommended for stateful server. |
||
25 | */ |
||
26 | public const DISPATCH_FIXED_MODE = 2; |
||
27 | |||
28 | /** |
||
29 | * Dispatch the connection to the unoccupied worker process. |
||
30 | * Recommended for stateless, synchronous and blocking server. |
||
31 | */ |
||
32 | public const DISPATCH_PREEMPTIVE_MODE = 3; |
||
33 | |||
34 | /** |
||
35 | * Dispatch the connection to the worker according to the ip of client. |
||
36 | * The dispatch algorithm is ip2long(ClientIP) % worker_num |
||
37 | */ |
||
38 | public const DISPATCH_IP_MODE = 4; |
||
39 | |||
40 | /** |
||
41 | * Used if none provided in the constructor |
||
42 | */ |
||
43 | public const DEFAULT_ADDRESS = '0.0.0.0'; |
||
44 | |||
45 | /** |
||
46 | * Used if none provided in the constructor |
||
47 | */ |
||
48 | public const DEFAULT_PORT = 80; |
||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | */ |
||
53 | private $settings = []; |
||
54 | |||
55 | /** |
||
56 | * HttpConfiguration constructor. |
||
57 | * |
||
58 | * @param string $address |
||
59 | * @param int $port |
||
60 | */ |
||
61 | 30 | public function __construct(int $port = self::DEFAULT_PORT, string $address = self::DEFAULT_ADDRESS) |
|
66 | |||
67 | 3 | public function getPort(): int |
|
71 | |||
72 | 3 | public function getAddress(): string |
|
76 | |||
77 | /** |
||
78 | * Checks if ssl is enabled. |
||
79 | * |
||
80 | * @return bool |
||
81 | */ |
||
82 | 1 | public function isSslEnabled(): bool |
|
86 | |||
87 | /** |
||
88 | * Enables ssl on the server |
||
89 | * |
||
90 | * @param string $certFile |
||
91 | * @param string $keyFile |
||
92 | */ |
||
93 | 4 | public function enableSsl(string $certFile, string $keyFile): void |
|
108 | |||
109 | /** |
||
110 | * Sets response compression level 0 - no compression 9 - high compression |
||
111 | * |
||
112 | * @param int $level |
||
113 | */ |
||
114 | public function setResponseCompression(int $level = 0): void |
||
118 | |||
119 | /** |
||
120 | * Checks if server is daemonized. |
||
121 | * |
||
122 | * @return bool |
||
123 | */ |
||
124 | 1 | public function isDaemonEnabled(): bool |
|
128 | |||
129 | /** |
||
130 | * Sets the max tcp connection number of the server. |
||
131 | * |
||
132 | * @param int $max |
||
133 | */ |
||
134 | 1 | public function setMaxConnections(int $max = 10000): void |
|
138 | |||
139 | /** |
||
140 | * Sets the number of worker processes. |
||
141 | * |
||
142 | * @param int $count |
||
143 | */ |
||
144 | 1 | public function setWorkers(int $count = 1): void |
|
148 | |||
149 | /** |
||
150 | * Sets the number of requests processed by the worker process before process manager recycles it. |
||
151 | * Once process is recycled (memory used by process is freed and process is killed) process manger |
||
152 | * will spawn new worker. |
||
153 | * |
||
154 | * @param int $max |
||
155 | */ |
||
156 | 1 | public function setMaxRequests(int $max = 0): void |
|
160 | |||
161 | /** |
||
162 | * Sets the maximum number of pending connections. This refers to the number of clients |
||
163 | * that can be waiting to be served. Exceeding this number results in the client getting |
||
164 | * an error when attempting to connect. |
||
165 | * |
||
166 | * @param int $max |
||
167 | */ |
||
168 | 1 | public function setMaximumBacklog(int $max = 0): void |
|
172 | |||
173 | /** |
||
174 | * Sets dispatch mode for child processes works only if the server is run in process mode. |
||
175 | * |
||
176 | * @param int $mode |
||
177 | */ |
||
178 | 1 | public function setDispatchMode(int $mode = self::DISPATCH_FIXED_MODE): void |
|
182 | |||
183 | /** |
||
184 | * Allows server to be run as a background process. |
||
185 | * |
||
186 | * @param string $pidFile |
||
187 | */ |
||
188 | 1 | public function enableDaemon(string $pidFile): void |
|
199 | |||
200 | /** |
||
201 | * Sets temporary dir for uploaded files |
||
202 | * |
||
203 | * @param string $dir |
||
204 | */ |
||
205 | 1 | public function setUploadDir(string $dir): void |
|
209 | |||
210 | /** |
||
211 | * Sets the group of worker and task worker process. |
||
212 | * @param string $group |
||
213 | */ |
||
214 | 1 | public function setOwnerGroup(string $group): void |
|
218 | |||
219 | /** |
||
220 | * Redirect the root path of worker process. |
||
221 | * @param string $dir |
||
222 | */ |
||
223 | 1 | public function setChroot(string $dir): void |
|
231 | |||
232 | /** |
||
233 | * Set the output buffer size in the memory. The default value is 2M. |
||
234 | * The data to send can't be larger than the $size every request. |
||
235 | * |
||
236 | * @param int $size bytes |
||
237 | */ |
||
238 | 1 | public function setBufferOutputSize(int $size = 2 * 1024 * 1024): void |
|
242 | |||
243 | /** |
||
244 | * Returns swoole compatible settings array. |
||
245 | * |
||
246 | * @return array |
||
247 | */ |
||
248 | 11 | public function toArray(): array |
|
252 | } |
||
253 |