Skip to content

How to use websockets in RR2 #1203

Answered by M-Porter
M-Porter asked this question in Q&A
Jul 6, 2022 · 2 comments · 8 replies
Discussion options

You must be logged in to vote

Per @rustatian

Before RR establishes a ws connection, RR redirects the http (before upgrading to ws connection) headers to the PHP worker. If the PHP worker returns non 200OK HTTP code, RR rejects such a connection.

Add a new route to /ws in your routes/web.php and return a valid PSR7 response (MUST BE PSR7!!!!).

<?php

// routes/web.php

// The route here should be same as defined in your .rr.yaml file. https://github.com/roadrunner-server/roadrunner/blob/4d8552df9fb578a2a4d3a541547f91e205661a9d/.rr.yaml#L879
Route::get('/ws', fn () => new \GuzzleHttp\Psr7\Response());

You can now connect to the Websocket with

ws = new WebSocket('ws://localhost:8000/ws');

and send a message from the se…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
6 replies
@rustatian
Comment options

@M-Porter
Comment options

@rustatian
Comment options

@M-Porter
Comment options

@M-Porter
Comment options

Comment options

You must be logged in to vote
2 replies
@rustatian
Comment options

@rustatian
Comment options

Answer selected by M-Porter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
R-question Question
2 participants