From c9256ca4861b76c313fc99b852ebd8dd8ef2e72d Mon Sep 17 00:00:00 2001 From: walkor Date: Thu, 2 Jan 2025 17:51:56 +0800 Subject: [PATCH] Update task.md --- resource/doc/zh-cn/others/task.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/resource/doc/zh-cn/others/task.md b/resource/doc/zh-cn/others/task.md index 3f3fbd9..c1aed2c 100755 --- a/resource/doc/zh-cn/others/task.md +++ b/resource/doc/zh-cn/others/task.md @@ -92,4 +92,32 @@ server { 这样客户端访问`域名.com/tast/xxx`时将会走单独的8686端口处理,不影响8787端口的请求处理。 +## 方案三 利用http chunked 异步分段发送数据 +#### 优点 +可以直接将数据返回给客户端 + +```php +connection; + $http = new \Workerman\Http\Client(); + $http->get('https://example.com/', function ($response) use ($connection) { + $connection->send(new Chunk($response->getBody())); + $connection->send(new Chunk('')); // 发送空的的chunk代表response结束 + }); + return response()->withHeaders([ + "Transfer-Encoding" => "chunked", + ]); + } +} +```