-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
questionFurther information is requestedFurther information is requested
Description
hyperf怎么判断前端连接已经断开了
使用connection_aborted() 和connection_status() 都不行 连接断开都是返回的0
`
public function streamResponse(Response $swresponse)
{
$response = \Hyperf\Support\make(ResponseInterface::class);
$eventStream = new \Hyperf\Engine\Http\EventStream($response->getConnection());
/* foreach ($result as $stream) {
$eventStream->write($stream['choices'][0]['text']);
}*/
//判断客户端是否断开
while (true) {
// 模拟动态生成的数据
$data = [
'time' => date('Y-m-d H:i:s'),
'message' => 'Hello, this is an SSE message.'
];
print_r($data);
// 向客户端发送事件
$eventStream->write("data: " . json_encode($data) . "\n\n");
// 休眠1秒,模拟事件流的间隔
usleep(1000000); // 1秒
}
$eventStream->end();
}`
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested