Skip to content

Commit 67e337d

Browse files
authored
[SwooleNyholm] Add option for swoole socket type (#80)
1 parent 0ad5b00 commit 67e337d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/swoole-nyholm/src/ServerFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ServerFactory
1515
'host' => '127.0.0.1',
1616
'port' => 8000,
1717
'mode' => 2, // SWOOLE_PROCESS
18+
'sock_type' => 1, // SWOOLE_SOCK_TCP
1819
'settings' => [],
1920
];
2021

@@ -31,13 +32,14 @@ public function __construct(array $options = [])
3132
$options['host'] = $options['host'] ?? $_SERVER['SWOOLE_HOST'] ?? $_ENV['SWOOLE_HOST'] ?? self::DEFAULT_OPTIONS['host'];
3233
$options['port'] = $options['port'] ?? $_SERVER['SWOOLE_PORT'] ?? $_ENV['SWOOLE_PORT'] ?? self::DEFAULT_OPTIONS['port'];
3334
$options['mode'] = $options['mode'] ?? $_SERVER['SWOOLE_MODE'] ?? $_ENV['SWOOLE_MODE'] ?? self::DEFAULT_OPTIONS['mode'];
35+
$options['sock_type'] = $options['sock_type'] ?? $_SERVER['SWOOLE_SOCK_TYPE'] ?? $_ENV['SWOOLE_SOCK_TYPE'] ?? self::DEFAULT_OPTIONS['sock_type'];
3436

3537
$this->options = array_replace_recursive(self::DEFAULT_OPTIONS, $options);
3638
}
3739

3840
public function createServer(callable $requestHandler): Server
3941
{
40-
$server = new Server($this->options['host'], (int) $this->options['port'], (int) $this->options['mode']);
42+
$server = new Server($this->options['host'], (int) $this->options['port'], (int) $this->options['mode'], (int) $this->options['sock_type']);
4143
$server->set($this->options['settings']);
4244
$server->on('request', $requestHandler);
4345

0 commit comments

Comments
 (0)