Swoole v4.6.2 版本發佈,Bug 修復版本

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

新增 API

  • 新增 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)
  • 修復當使用 thread context 的時候,錯誤設置 Coroutine\Socket::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)

相關文章
相關標籤/搜索