Async WebSocket client for PHP based on Amp.
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
examples Add echo example with public echo server Dec 17, 2017
lib Fix close code byte order and pass it to the close function (#15) Dec 13, 2018
test-autobahn Run autobahn tests on Travis Dec 18, 2017
test Ignore backpressure if receive has been called again Dec 16, 2017
.editorconfig Fix .editorconfig Dec 15, 2017
.gitattributes Initial commit Dec 16, 2015
.gitignore Actually fix the code style Dec 15, 2017
.gitmodules Add docs Dec 23, 2017
.php_cs.dist Actually fix the code style Dec 15, 2017
.travis.yml Run autobahn tests on Travis Dec 18, 2017
CONTRIBUTING.md Initial commit Dec 16, 2015
LICENSE Update meta files and code style Dec 15, 2017
README.md Simplify receive() API and require explicit Message::buffer() calls Dec 16, 2017
composer.json
phpunit.xml.dist

README.md

websocket

Build Status CoverageStatus License

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

Installation

This package can be installed as a Composer dependency.

composer require amphp/websocket

Requirements

  • PHP 7.0+

Documentation & Examples

More extensive code examples reside in the examples directory.

use Amp\Delayed;
use Amp\Websocket;

// Connects to the websocket endpoint in demo.php provided with Aerys (https://github.com/amphp/aerys).
Amp\Loop::run(function () {
    /** @var \Amp\Websocket\Connection $connection */
    $connection = yield Websocket\connect("ws://localhost:1337/ws");
    yield $connection->send("Hello!");

    $i = 0;

    while ($message = yield $connection->receive()) {
        $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 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.