Computer Science, asked by magaldeep2222, 1 year ago

Eventsource's response has a mime type ("text/html") that is not "text/event-stream". Aborting the connection html sse

Answers

Answered by sunnybunny98
0

Answer:

I'm testing out react with addition of clue/php-sse-reactt, but can't make it work properly.

I'm using server like in the example:

require __DIR__ . '/../vendor/autoload.php'; use Clue\React\Sse\BufferedChannel; use React\Http\Request; use React\Http\Response; $loop = React\EventLoop\Factory::create(); $socket = new React\Socket\Server($loop); $channel = new BufferedChannel(); $http = new React\Http\Server($socket); $http->on('request', function (Request $request, Response $response) use ($channel) { echo 'connected' . PHP_EOL; $headers = $request->getHeaders(); $id = isset($headers['Last-Event-ID']) ? $headers['Last-Event-ID'] : null; $response->writeHead(200, array('Content-Type' => 'text/event-stream', 'Cache-Control' => 'no-cache')); $channel->connect($response, $id); $response->on('close', function () use ($response, $channel) { echo 'disconnected' . PHP_EOL; $channel->disconnect($response); }); }); $loop->addPeriodicTimer(2.0, function() use ($channel) { $channel->writeMessage('ticking ' . mt_rand(1, 5) . '...'); }); $socket->listen(1337); echo 'Server now listening on localhost:' . $socket->getPort() . PHP_EOL; $loop->run();

Similar questions