v4.6.2 版本主要是一個 Bug 修復版本,沒有向下不兼容改動。php
新增了 Coroutine\Socket->recvLine()
和 Coroutine\Socket->readWithBuffer()
方法html
分別用於解決 socket_read 兼容性問題和使用 recv(1)
逐字節接收時產生大量系統調用問題git
同時加強了 Response\create()
方法,能夠獨立於 Server 使用,如:github
use Swoole\Coroutine\Server; use Swoole\Coroutine\Server\Connection; use Swoole\Http\Request; use Swoole\Http\Response; Swoole\Coroutine\run(function () { $server = new Server('0.0.0.0', 9501, false); go(function () use ($server) { $server->handle(function (Connection $conn) use ($server) { $req = Request::create(); while(true) { $data = $conn->recv(); if (strlen($data) != $req->parse($data) or $req->isCompleted()) { break; } } var_dump($req->get); $resp = Response::create([$conn->exportSocket(), $req]); $resp->header('X-Server', 'swoole'); $resp->end('Hello, Swoole'); $server->shutdown(); }); $server->start(); }); });
啓動後使用 curl 發起請求macos
$ curl -I http://127.0.0.1:9501/\?hello\=swoole HTTP/1.1 200 OK X-Server: swoole Server: swoole-http-server Connection: keep-alive Content-Type: text/html Date: Mon, 25 Jan 2021 10:58:31 GMT Content-Length: 13 $ curl http://127.0.0.1:9501/\?hello\=swoole Hello, Swoole
而終端會打印請求中的 GET 參數bash
array(1) { ["hello"]=> string(6) "swoole" }
下面是完整的更新日誌:swoole
Http\Request\getMethod()
方法 (#3987) (@luolaifa000)Coroutine\Socket->recvLine()
方法 (#4014) (@matyhtf)Coroutine\Socket->readWithBuffer()
方法 (#4017) (@matyhtf)Response\create()
方法,能夠獨立於 Server 使用 (#3998) (@matyhtf)Coroutine\Redis->hExists
在設置了 compatibility_mode 以後返回 bool 類型 (swoole/swoole-src@b8cce7c) (@matyhtf)socket_read
設置 PHP_NORMAL_READ 選項 (swoole/swoole-src@b1a0dcc) (@matyhtf)Coroutine::defer
在 PHP8 下 coredump 的問題 (#3997) (@huanghantao)Coroutine\Socket::errCode
的問題 (swoole/swoole-src@004d08a) (@matyhtf)Process::wait()
(#4019) (@matyhtf)