Skip to content

Commit a8cd7b2

Browse files
committed
Adjust Swoole adapter for non-coroutine server
1 parent 9b0f4fb commit a8cd7b2

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/Adapter/Swoole/Server.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,27 @@
22

33
namespace Utopia\Adapter\Swoole;
44

5-
use Swoole\Coroutine;
65
use Utopia\Adapter\Adapter;
7-
use Swoole\Coroutine\Http\Server as SwooleServer;
6+
use Swoole\Http\Server as SwooleServer;
87
use Swoole\Http\Request as SwooleRequest;
98
use Swoole\Http\Response as SwooleResponse;
109
use Utopia\Http;
1110

12-
use function Swoole\Coroutine\run;
13-
1411
class Server extends Adapter
1512
{
1613
protected SwooleServer $server;
1714

1815
public function __construct(string $host, ?string $port = null, array $settings = [])
1916
{
2017
$this->server = new SwooleServer($host, $port);
21-
$this->server->set(\array_merge($settings, [
22-
'enable_coroutine' => true,
23-
'http_parse_cookie' => false,
24-
]));
18+
if (!empty($settings)) {
19+
$this->server->set($settings);
20+
}
2521
}
2622

2723
public function onRequest(callable $callback)
2824
{
29-
$this->server->handle('/', function (SwooleRequest $request, SwooleResponse $response) use ($callback) {
25+
$this->server->on('request', function (SwooleRequest $request, SwooleResponse $response) use ($callback) {
3026
Http::setResource('swooleRequest', fn () => $request);
3127
Http::setResource('swooleResponse', fn () => $response);
3228

@@ -41,10 +37,6 @@ public function onStart(callable $callback)
4137

4238
public function start()
4339
{
44-
if (Coroutine::getCid() === -1) {
45-
run(fn () => $this->server->start());
46-
} else {
47-
$this->server->start();
48-
}
40+
$this->server->start();
4941
}
5042
}

0 commit comments

Comments
 (0)