amphp / websocket-client
Async WebSocket client for PHP based on Amp.
Fund package maintenance!
amphp
Installs: 624 318
Dependents: 30
Suggesters: 0
Security: 0
Stars: 123
Watchers: 16
Forks: 18
Open Issues: 7
Requires
- php: >=8.1
- amphp/amp: ^3
- amphp/byte-stream: ^2
- amphp/http: ^2
- amphp/http-client: ^5
- amphp/socket: ^2
- amphp/websocket: ^2
- league/uri: ^6
- psr/http-message: ^1
- revolt/event-loop: ^1
Requires (Dev)
- amphp/http-server: ^3
- amphp/php-cs-fixer-config: ^2
- amphp/phpunit-util: ^3
- amphp/websocket-server: ^3
- phpunit/phpunit: ^9
- psalm/phar: ^5.4
- psr/log: ^1
This package is auto-updated.
Last update: 2023-05-26 04:04:47 UTC
README
amphp/websocket-client
is an async WebSocket client for PHP based on Amp.
Installation
This package can be installed as a Composer dependency.
composer require amphp/websocket-client
Requirements
- PHP 8.1+
Documentation & Examples
More extensive code examples reside in the examples
directory.
use Amp\Websocket\Client\WebsocketHandshake; use function Amp\Websocket\Client\connect; // Connects to the websocket endpoint at libwebsockets.org which sends a message every 50ms. $handshake = (new WebsocketHandshake('wss://libwebsockets.org')) ->withHeader('Sec-WebSocket-Protocol', 'dumb-increment-protocol'); $connection = connect($handshake); while ($message = $connection->receive()) { $payload = $message->buffer(); printf("Received: %s\n", $payload); if ($payload === '100') { $connection->close(); break; } }
Versioning
amphp/websocket-client
follows the semver semantic versioning specification like all other amphp
packages.
Security
If you discover any security related issues, please email contact@amphp.org
instead of using the issue tracker.
License
The MIT License (MIT). Please see LICENSE
for more information.