首页
文档
问答
捐赠
源代码
商业产品
Swoole Tracker
Swoole Plus
Swoole Compiler
Swoole 微课程
商业合作
登录
注册
EN
全部
提问
分享
讨论
建议
公告
开发框架
发表新帖
Swoole v4.6.2 版本发布,Bug 修复版本
鲁飞
2个月前
[v4.6.2](https://github.com/swoole/swoole-src/releases/tag/v4.6.2) 版本主要是一个 Bug 修复版本,没有向下不兼容改动。 新增了 `Coroutine\Socket->recvLine()` 和 `Coroutine\Socket->readWithBuffer()` 方法 分别用于解决 [socket_read](https://www.php.net/manual/en/function.socket-read.php) 兼容性问题和使用 `recv(1)` 逐字节接收时产生大量系统调用问题 同时增强了 `Response\create()` 方法,可以独立于 Server 使用,如: ```php 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 发起请求 ```bash $ 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" } ``` 下面是完整的更新日志: ### 新增 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/b8cce7c) (@matyhtf) - 支持 `socket_read` 设置 PHP_NORMAL_READ 选项 (b1a0dcc) (@matyhtf) ### 修复 - 修复 `Coroutine::defer` 在 PHP8 下 coredump 的问题 (#3997) (@huanghantao) - 修复当使用 thread context 的时候,错误设置 `Coroutine\Socket::errCode` 的问题 (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) 
评论
还没有评论!