Closed shizzic closed 1 week ago
https://manual.workerman.net/doc/en/http/SSE.html Here is an example of SSE. Please test if this example works. If it does, try adding your configuration and business code, which might help quickly identify the issue.
https://manual.workerman.net/doc/en/http/SSE.html Here is an example of SSE. Please test if this example works. If it does, try adding your configuration and business code, which might help quickly identify the issue.
Commented my whole code, paste your example from docs like this:
$this->worker->onMessage = function (TcpConnection $connection, Request $request) {
if ($request->header('accept') === 'text/event-stream') {
$connection->send(new Response(200, [
'Access-Control-Allow-Origin' => rtrim($request->header('Referer'), '/'),
'Access-Control-Allow-Credentials' => 'true',
'Content-Type' => 'text/event-stream',
], "\r\n"));
$timer_id = Timer::add(2, function () use ($connection, &$timer_id) {
if ($connection->getStatus() !== TcpConnection::STATUS_ESTABLISHED) {
Timer::del($timer_id);
return;
}
$connection->send(new ServerSentEvents(['event' => 'message', 'data' => 'hello', 'id' => 1]));
});
return;
}
$connection->send('ok');
};
Needed to specify allow-origin, bacause my front and back are seperated. '*' doesn't work, it's need to be specified with specific names, that's why i trim Referer header. Results are the same, chrome works fine (i get EventStream responses as messages every 2 seconds) and firefox doesn't (every network tab: headers, cookie, response, request, timings are blank).
Sorry, turns out Firefox doesn't have good network client for tracing SSE in browser's devtools. It worked all along, i just needed to console.log
messages i got. All that time i thought i didn't have a connection in the first place.
Shortly (as i can be in this issue). Workerman's code:
The thing is, presented code (simplified ofc) works in all browsers on chromium and doesn't on Firefox (clones included). Moreover, if i try to connect to sse on Firefox, than network shows nothing, just blank spaces everywhere (headers, cookies, request, response) all of em. There are 2 keys in config, which are
verify_peer
andverify_peer_name
and if i set em to true, than i see headers and basically everything in Firefox (still no established connection btw) and with true chromium based browsers can't conenct to.Funny thing is, with false (normal i guess, it works at least) i can
print_r()
anyting in stdoutFile even AFTERnew Response
send. So it's connected, and should return 200 status response, but not... (chromium works just fine just to remind).Am i missing somethind, what do i do wrong, is it my problem, is it Firefox issue, can i do anything about it? Certificate is alright, i have chains (workerman's config included above). You can check it with any ssl certificate checker It's a test domain anyway.