amphp/websocket-client
Async WebSocket client for PHP based on Amp.
v2.0.2
7.1M downloads/mo
#609 most downloaded on Packagist
amphp/websocket-client
What this package is like to depend on
Last release 12 months ago
24 Aug 2025
Ships fairly regularly
a new release about every 6 months
Some releases are documented
notes for 5 of 11 stable releases
Nothing withdrawn
no release was ever pulled
10 years old
17 releases · first in 2016
0 releases in the last 12 months
see the full history below
Release timeline
17 releases · Nov 2016 to Aug 2025Releases
latest 17-
v2.0.224 Aug 2025 -
v2.0.107 Dec 2024Release notes
Open source →What's Changed
- Fix missing semicolon in readme by @nimah79 in #50
- Make Rfc6455Connector compatible with PHP 8.4 by @foxycode in #53
New Contributors
Full Changelog: v2.0.0...v2.0.1
-
v2.0.028 Dec 2023Release notes
Open source →Stable release compatible with AMPHP v3 and fibers! 🎉
As with other libraries compatible with AMPHP v3, most cases of parameters or returns of
Promise<ResolutionType>have been replaced withResolutionType.This release is compatible with
amphp/http-client@^5andamphp/websocket@^2. See the release notes of these libraries for further change notes.Similar to
v1, a Websocket connection is created usingAmp\Websocket\Client\connect()or using an instance ofWebsocketConnector, callingWebsocketConnector::connect(). The returnedWebsocketConnectionthen is used to send and receive WebSocket messages.- Renamed most classes and interfaces to add
Websocketas a prefix to avoid name collisions with similarly named classes in other packages which are frequently used together. For example,Connectionis nowWebsocketConnection. - Advanced handshake and connection parameters may be specified using a
Rfc6455ConnectionFactoryinstance provided when constructing aRfc6455Connector. - A global
WebsocketConnectorinstance may be accessed and set viaAmp\Websocket\Client\websocketConnector().
Release notes
Open source →- Compatibility with
amphp/http@v2 - Added query-related methods to
WebsocketHandshake
Release notes
Open source →- Updated for compatibility with
amphp/socket@v2andamphp/[email protected] - Altered
Rfc6455ConnectionFactoryconstructor to use an instance ofWebsocketParserFactory, moving some configuration options toRfc6455ParserFactory
Release notes
Open source →Initial release compatible with AMPHP v3.
As with other libraries compatible with AMPHP v3, most cases of parameters or returns of
Promise<ResolutionType>have been replaced withResolutionType.- Added
Websocketas a prefix to several classes:Connectionrenamed toWebsocketConnectionConnectionFactoryrenamed toWebsocketConnectionFactoryConnectorrenamed toWebsocketConnectorConnectionExceptionrenamed toWebsocketConnectExceptionHandshakerenamed toWebsocketHandshake
- Renamed
connectorfunction towebsocketConnector
- Renamed most classes and interfaces to add
-
v2.0.0-beta.420 Oct 2023 pre-releaseNothing published for this version
-
v2.0.0-beta.326 Apr 2023 pre-releaseNothing published for this version
-
v2.0.0-beta.206 Feb 2023 pre-releaseNothing published for this version
-
v2.0.0-beta.105 Jun 2022 pre-releaseNothing published for this version
-
v1.0.110 Mar 2022Release notes
Open source →- Ignore
/docsin.gitattributesto avoid broken symlink (#38)
Full Changelog: v1.0.0...v1.0.1
- Ignore
-
v1.0.005 Jul 2020Release notes
Open source →Changes since RC2
- Removed header methods from
Connection. Now theResponseobject is available withConnection::getResponse(), which provides access to the response headers and other response data. - Removed the
connector()function, so there is no longer a globalConnectorobject. - Fixed
Handshake::withHeaders()to remove all prior set headers as expected. - Added
ConnectContextparameter toconnect()function. ConnectionExceptionnow extendsHttpExceptionfromamphp/http-client.
Upgrading from v0.2.x to v1.0
This library has been refactored to use the new
amphp/websocketlibrary containing components that can be shared between server and clients.The simplest way to use this library is with the
connect()function to initiate a WebSocket connection.$connection = yield Amp\Websocket\Client\connect('ws://localhost:1337/broadcast'); yield $connection->send('Hello!'); /** @var Amp\Websocket\Message $message */ while ($message = yield $connection->receive()) { $payload = yield $message->buffer(); // $payload now contains the entire message content yield $connection->send('Received message with length ' . strlen($payload)); }
Custom request headers and connections options can be set using the
Handshakeclass and passing this object toconnect()instead of a string URI. Connection behavior can be further customized by using an instance ofConnectorto establish a connection instead of theconnect()function.WebSocket clients are now represented by
Connection, which extends theClientobject fromamphp/websocket. This object contains several methods for getting information about the client, fetching the headers returned in the server response, and sending/receiving messages.Release notes
Open source →- This library now uses
HttpClientfromamphp/http-clientto send connection requests. As such,Rfc6455Connectorrequires an instance ofHttpClientwhen constructed. The client may have various interceptors attached to modify behavior when connecting. - Updated to
league/uri@^6, subsequently PHP 7.2+ is now required.
- Removed header methods from
-
v1.0.0-rc226 Feb 2020 pre-releaseNothing published for this version
-
v1.0.0-rc122 Aug 2019 pre-releaseNothing published for this version
-
v0.2.406 Feb 2019Nothing published for this version
-
v0.2.330 Jan 2019Nothing published for this version
-
v0.2.218 Dec 2017Nothing published for this version
-
v0.2.117 Dec 2017Nothing published for this version
-
v0.2.016 Dec 2017Nothing published for this version
-
v0.1.016 Nov 2016Nothing published for this version