page contents

Swoole v4.6.2 版本发布,Bug 修复版本

v4.6.2 版本主要是一个 Bug 修复版本,没有向下不兼容改动。

attachments-2021-02-n9CINdMo6017adccb4ac8.png


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'9501false);
    go(function () use ($server) {
        $server->handle(function (Connection $connuse ($server) {
            $req = Request::create();
            while(true) {
                $data $conn->recv();
                if (strlen($data) != $req->parse($dataor $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)


attachments-2021-02-np77vCdb6017add8c0311.jpg

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
轩辕小不懂
轩辕小不懂

2403 篇文章

作家榜 »

  1. 轩辕小不懂 2403 文章
  2. 小柒 1320 文章
  3. Pack 1135 文章
  4. Nen 576 文章
  5. 王昭君 209 文章
  6. 文双 71 文章
  7. 小威 64 文章
  8. Cara 36 文章