Skip to content

Conversation

@tw2066
Copy link

通过增加write返回值;
1:可以判断客户端是否离线(返回false)
2:离线后可以做后续判断

/** @var Response $response */$response = ApplicationContext::getContainer()->get(ResponseInterface::class); $result = [ 'data: 1' . PHP_EOL . PHP_EOL, 'data: 2' . PHP_EOL . PHP_EOL, 'data: 3' . PHP_EOL . PHP_EOL, 'data: 4' . PHP_EOL . PHP_EOL, 'data: 5' . PHP_EOL . PHP_EOL, 'data: 6' . PHP_EOL . PHP_EOL, ]; $eventStream = newEventStream($response->getConnection()); foreach ($resultas$stream){$bool = $eventStream->write((string) $stream); dump($bool,$stream); if (! $bool){return} sleep(3)} $eventStream->end();

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@tw2066