Skip to content
Async WebSocket client for PHP based on Amp.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Update Handshake Feb 10, 2019
src Update for getId() returning a string Apr 6, 2019
test-autobahn Update for Options named constructors Mar 29, 2019
.editorconfig Fix .editorconfig Dec 15, 2017
.gitattributes Initial commit Dec 16, 2015
.gitignore Update PHPUnit config Feb 8, 2019
.travis.yml Refactor based on common amphp/websocket repo Feb 6, 2019 Initial commit Dec 16, 2015
LICENSE Update meta files and code style Dec 15, 2017 Update README Feb 7, 2019
composer.json Use tagged amphp/http Mar 27, 2019


Build Status CoverageStatus License

amphp/websocket-client is an async WebSocket client for PHP based on Amp.


This package can be installed as a Composer dependency.

composer require amphp/websocket-client


  • PHP 7.1+

Documentation & Examples

More extensive code examples reside in the examples directory.

use Amp\Delayed;
use Amp\Websocket\Client\Connection;
use Amp\Websocket\Message;
use function Amp\Websocket\Client\connect;

// Connects to the Kaazing echoing websocket demo.
Amp\Loop::run(function () {
    /** @var Connection $connection */
    $connection = yield connect('ws://');
    yield $connection->send("Hello!");

    $i = 0;

    while ($message = yield $connection->receive()) {
        /** @var Message $message */
        $payload = yield $message->buffer();
        printf("Received: %s\n", $payload);

        if ($payload === "Goodbye!") {

        yield new Delayed(1000);

        if ($i < 3) {
            yield $connection->send("Ping: " . ++$i);
        } else {
            yield $connection->send("Goodbye!");


amphp/websocket-client follows the semver semantic versioning specification like all other amphp packages.


If you discover any security related issues, please email instead of using the issue tracker.


The MIT License (MIT). Please see LICENSE for more information.

You can’t perform that action at this time.