Skip to content

Commit 6487fab

Browse files
committed
keep original server
1 parent aedf29b commit 6487fab

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

src/Http/Adapter/Swoole/Server.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
namespace Utopia\Http\Adapter\Swoole;
44

5-
use Swoole\Coroutine;
65
use Utopia\Http\Adapter;
7-
use Swoole\Coroutine\Http\Server as SwooleServer;
8-
use Swoole\Http\Request as SwooleRequest;
9-
use Swoole\Http\Response as SwooleResponse;
10-
11-
use function Swoole\Coroutine\run;
6+
use Swoole\Http\Server as SwooleServer;
127

138
class Server extends Adapter
149
{
@@ -17,32 +12,32 @@ class Server extends Adapter
1712
public function __construct(string $host, ?string $port = null, array $settings = [])
1813
{
1914
$this->server = new SwooleServer($host, $port);
20-
$this->server->set(array_merge([
15+
$this->server->set(\array_merge($settings, [
2116
'open_http2_protocol' => true,
2217
'dispatch_mode' => 2,
23-
'enable_coroutine' => true,
24-
'http_parse_cookie' => false,
25-
], $settings));
18+
]));
2619
}
2720

2821
public function onRequest(callable $callback)
2922
{
30-
$this->server->handle('/', function (SwooleRequest $request, SwooleResponse $response) use ($callback) {
31-
call_user_func($callback, $request, $response);
23+
$this->server->on('request', function ($request, $response) use ($callback) {
24+
go(function () use ($request, $response, $callback) {
25+
call_user_func($callback, new Request($request), new Response($response));
26+
});
3227
});
3328
}
3429

3530
public function onStart(callable $callback)
3631
{
37-
call_user_func($callback, $this);
32+
$this->server->on('start', function () use ($callback) {
33+
go(function () use ($callback) {
34+
call_user_func($callback);
35+
});
36+
});
3837
}
3938

4039
public function start()
4140
{
42-
if (Coroutine::getCid() === -1) {
43-
run(fn () => $this->server->start());
44-
} else {
45-
$this->server->start();
46-
}
41+
return $this->server->start();
4742
}
48-
}
43+
}

0 commit comments

Comments
 (0)