-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_creation_params.php
39 lines (36 loc) · 1.15 KB
/
service_creation_params.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
ini_set("register_argc_argv", true);
$serverProtocol='';
if (isset($argv[1]) && in_array($argv[1], ['reload-code', 'restart', 'shutdown', 'websocket', 'http','http2', 'tcp', 'udp', 'mqtt', 'grpc', 'socket'])) { // Set Default IP
$serverProtocol = $argv[1];
} else {
$serverProtocol = 'http';
}
if (isset($argv[2])) { // Set Default IP
$ip = $argv[2];
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
echo "Invalid format of IP address";
exit;
}
} else {
$ip = "0.0.0.0";
}
// Default port 9501
$port = '9501';
if (isset($argv[3]) &&
preg_match('^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$', $argv[3])) {
$port = $argv[3];
}
$serverMode='';
// Default Server Mode
// Ref.: https://openswoole.com/docs/modules/swoole-server-construct
if (isset($argv[3])) {
$serverMode = $argv[3];
if (strtoupper($serverMode) == 'SWOOLE_PROCESS') {
$serverMode = SWOOLE_PROCESS; // OpenSwoole\Server::POOL_MODE
} else {
$serverMode = SWOOLE_BASE; // OpenSwoole\Server::SIMPLE_MODE
}
} else {
$serverMode = SWOOLE_PROCESS; // Default Mode: OpenSwoole\Server::POOL_MODE
}