Skip to content
Async WebSocket client for PHP based on Amp.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
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
test
.editorconfig Fix .editorconfig Dec 15, 2017
.gitattributes Initial commit Dec 16, 2015
.gitignore Update PHPUnit config Feb 8, 2019
.gitmodules
.php_cs.dist
.travis.yml Refactor based on common amphp/websocket repo Feb 6, 2019
CONTRIBUTING.md Initial commit Dec 16, 2015
LICENSE Update meta files and code style Dec 15, 2017
README.md Update README Feb 7, 2019
composer.json Use tagged amphp/http Mar 27, 2019
phpunit.xml.dist

README.md

websocket-client

Build Status CoverageStatus License

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 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://demos.kaazing.com/echo');
    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!") {
            $connection->close();
            break;
        }

        yield new Delayed(1000);

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

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.

You can’t perform that action at this time.