1

I cant figure out, how to pass variables to websocket. For example, I get calculations before launching websocket, and I would love to pass results to websocket, to compare them on each update until I get result I'm waiting for. Is there a way to do it? I was able to kind if make it work by creating cache, and reading it on message update, but takes way too much resources, and memory gets clogged very fast.

$variable = 151481;

\Ratchet\Client\connect('wss://fstream.binance.com/stream?streams='.$pairs)->then(function($conn) {
    $conn->on('message', function($msg) use ($conn) {
        $result = json_decode($msg);

        $open = $result->data->k->o;
        $close = $result->data->k->c;

        //REQUIRED VARIABLE 
        //$variable = ??;

    });
}, function ($e) {
    echo "Could not connect: {$e->getMessage()}\n";
 });

1 Answer 1

1

I was able to pass variables with $GLOBALS['variable']; With these I can pass values from one websocket message to another and memory resources usage is fairly low.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.