Documentation / Migration v1 -> v2
Version 2.x has significant changes compared to previous version.
Amongst other things, it introduces callback listeners, middleware support, and the Server now support multiple connections.
Where 1.x was configured by using an array of options on the constructor,
2.x provides a number of configuration methods instead.
Replace configuration with a call to corresponding method instead.
new WebSocket\Client(string $uri)
new WebSocket\Server(bool $ssl, int $port)
setLogger(Psr\Log\LoggerInterface $logger) // logger
setTimeout(int $timeout) // timeout
setFrameSize(int $frameSize) // fragment_size
setPersistent(bool $persistent) // persistent
setContext(array $context_as_array) // context
addHeader(string $name, string $value) // headersThe filter and return_obj are no longer valid.
2.x introduces middlewares to extend functionality to Client and Server.
Two of the middlewares cover functionality built-in in 1.x and should be added unless you create your own code instead.
addMiddleware(new WebSocket\Middleware\CloseHandler())
addMiddleware(new WebSocket\Middleware\PingResponder())The Client receive() method always return an instance of Message (Text, Binary, Ping, Pong or Close).
This corresponds to setting return_obj: true in 1.x configuration. By default 1.x returned string.
You are encouraged to read incoming messages using listener callback methods instead.
The Server no longer has the receive() method.
Receiving, use listener callback methods.
The send(...) method no longer accepts message and opcode as strings,
but only accepts an instance of Message (Text, Binary, Ping, Pong or Close).
However, there are convenience methods available as text(...), binary(...), ping(...), pong(...) and close(...).
As 2.x has significant internal code changes, other classes and methods are likely to have changed.