amphp / websocket-client

Async WebSocket client for PHP based on Amp.

Home Page:https://amphp.org/websocket-client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Call to undefined method Amp\Coroutine::receive()

mnapoli opened this issue · comments

I tried the example from the README and I'm getting an error on the receive() call:

Call to undefined method Amp\Coroutine::receive()

<?php

require 'vendor/autoload.php';

use Amp\Websocket\Client;

$connection = Client\connect('ws://localhost:1337/ws');

while ($message = $connection->receive()) {
    $payload = $message->buffer();

    printf("Received: %s\n", $payload);

    if ($payload === '100') {
        $connection->close();
        break;
    }
}

Am I missing something obvious?

This suspiciously sounds like you've checked out 1.x instead of 2.x?

Oh right… there's no stable 2.x. Should I go with 2.x still? Is the website documentation targeting 2.x?

(I'm new with Amp, I'm looking at the simplest onboarding possible 😅)

Yes, use the library versions compatible with Amp v3.

Well v1 installed Amp v3 but is that what you are saying?

V1 should install Amp v2, v2 should install Amp v3.

We now have a stable 2.0.0 release, so I guess we can close this :-)