paragi / PHP-websocket-client

142 stars 61 forks source link

read method problem, Reading header from websocket failed #23

Open gspgsp opened 2 years ago

Trismegiste commented 2 years ago

Can you provide some details, please ? What websocket server did you use ? What kind of error do you encounter ?

I'm currently using the header option in this project : https://github.com/Trismegiste/eclipse-wiki/blob/master/src/Service/WebsocketPusher.php#L44 and I don't encounter any issue.

In anyway, thanks for your feedback

maxmistral commented 2 years ago

Hello here ! I wanted to point out the same problem I encountered when using your library for a project : Fatal error: Uncaught Paragi\PhpWebsocket\ConnectionException: Reading header from websocket failed. in C:\WebServer\htdocs\includes\Framework\WebSocket\Client.php:233

paragi commented 2 years ago

The error text might not be altogether that informative, though technically correct. This is do to a read timeout.

Trismegiste commented 2 years ago

Uncaught Paragi\PhpWebsocket\ConnectionException

I don't know about your code but obviously you didn't catch exception. More info on https://github.com/paragi/PHP-websocket-client#exception

maxmistral commented 2 years ago

The page loads a few milliseconds before displaying this error despite a timeout set to 5 seconds. In fact, the error appears once on ~10 refreshes of my page. It seems that when this happens, the server receives a request to open a connection but does not receive the message sent with the write() function. I specify that my WebSocket sessions are temporary and used only for sending and receiving a single message. I repeat the operation each time I need to consume a different path of the api. It's true that I don't use try catch but I can't understand why the WebSocket server doesn't receive the request sent by the php client.

chwpi commented 1 year ago

The page loads a few milliseconds before displaying this error despite a timeout set to 5 seconds. In fact, the error appears once on ~10 refreshes of my page. It seems that when this happens, the server receives a request to open a connection but does not receive the message sent with the write() function. I specify that my WebSocket sessions are temporary and used only for sending and receiving a single message. I repeat the operation each time I need to consume a different path of the api. It's true that I don't use try catch but I can't understand why the WebSocket server doesn't receive the request sent by the php client.

on Tornado websocket server, Tornado is not correct and uses 'Sec-Websocket-Accept: ', but it should be 'Sec-WebSocket-Accept: ' Reading RFC6455 Tornado is at fault unless the response header is not case sensitive. This codebase is case sensitive.

Change the websocket_open function response header to either case insensitive, or correct the one letter that is wrong coming from Tornado