v4.6.2 版本主要是一個 Bug 修復版本,沒有向下不兼容改動。
新增了 CoroutineSocket->recvLine() 和 CoroutineSocket->readWithBuffer() 方法
分別用於解決 socket_read 兼容性問題和使用 recv(1) 逐字節接收時產生大量系統調用問題
同時增強了 Responsecreate() 方法,可以獨立於 Server 使用,如:
`use SwooleCoroutineServer; use SwooleCoroutineServerConnection; use SwooleHttpRequest; use SwooleHttpResponse; SwooleCoroutinerun(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 發起請求
`$ 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 參數
`array(1) { ["hello"]=> string(6) "swoole" } `
下面是完整的更新日誌:
新增 API
- 新增 HttpRequestgetMethod() 方法 (#3987) (@luolaifa000)
- 新增 CoroutineSocket->recvLine() 方法 (#4014) (@matyhtf)
- 新增 CoroutineSocket->readWithBuffer() 方法 (#4017) (@matyhtf)
增強
- 增強 Responsecreate() 方法,可以獨立於 Server 使用 (#3998) (@matyhtf)
- 支持 CoroutineRedis->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)
- 修復當使用 thread context 的時候,錯誤設置 CoroutineSocket::errCode 的問題 (swoole/swoole-src@004d08a) (@matyhtf)
- 修復在最新的 macos 下 Swoole 編譯失敗的問題 (#4007) (@matyhtf)
- 修復當 md5_file 參數傳入 url 導致 php stream context 爲空指針的問題 (#4016) (@ZhiyangLeeCN)
內核
- 使用 AIO 線程池 hook stdio(解決之前把 stdio 視爲 socket 導致的多協程讀寫問題) (#4002) (@matyhtf)
- 重構 HttpContext (#3998) (@matyhtf)
- 重構 Process::wait() (#4019) (@matyhtf)