O
O
Octoberfest2016-12-17 18:11:06
PHP
Octoberfest, 2016-12-17 18:11:06

How to connect from php(client) to Socket.io server?

Hello. We are trying to connect to the Online PBX service via the Websocket API, all the script logic is written in php, so we decided to make a simple client in php too, this is the only module that should be done in js, but alas, no.
Problem. OnlinePBX has a library for interacting with the API , but the API itself doesn't suit us either .
Right now I'm trying to connect to them using Ratchetphp Pawl like this:

$loop = React\EventLoop\Factory::create();
    $connector = new Ratchet\Client\Connector($loop);
    $connector('ws://crmgt4u.onpbx.ru:8094')->then(function(Ratchet\Client\WebSocket $conn) {
        $conn->send('{"domain":"МОЙ ДОМЕН","key":"МОЙ КЛЮЧ","port":8094}');

    $conn->on('message', function(\Ratchet\RFC6455\Messaging\MessageInterface $msg) use ($conn) {
            echo "Получены данные: {$msg}\n";
            $conn->close();
        });

  }, function(\Exception $e) use ($loop) {
        echo "Нет соединения: {$e->getMessage()}\n";
        $loop->stop();
    });

    $loop->run();

What could be the problem? Gives the error "No connection: Connection closed before handshake". Maybe I need Elephant.io ? If so, can anyone who has worked with Elephantio provide examples?
PS or do you still need js? We only need a connection to "listen" to the channel, nothing more.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Balin, 2016-12-22
@krocos

Be PHP! Use Swoole! ^_^

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question