Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

EventStream add return value #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tw2066 wants to merge 2 commits into hyperf:master
base: master
Choose a base branch
Loading
from tw2066:sse
Open

EventStream add return value #35

tw2066 wants to merge 2 commits into hyperf:master from tw2066:sse

Conversation

@tw2066
Copy link

@tw2066 tw2066 commented Feb 11, 2025

通过增加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 = new EventStream($response->getConnection());
 foreach ($result as $stream) {
 $bool = $eventStream->write((string) $stream);
 dump($bool,$stream);
 if (! $bool) {
 return;
 }
 sleep(3);
 }
 $eventStream->end();

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /