Basically, I can't use $bidPrice in my code, even though I defined it as global. Inside the If construct it's assigned a value, but outside it's still seen as undefined, for example, if I wanted to use $askPrice or $bidPrice in a function outside of the if clause.
I've also tried to define it as global inside the if clause, didn't work either.
I'm thankful for any answers :)
global $askPrice;
global $bidPrice;
echo "\r";
\Ratchet\Client\connect('wss://www.bitmex.com/realtime')->then(function($conn) {
$conn->on('message', function($msg) use ($conn) {
if(str_replace('"askPrice":', "", strstr(strstr(strstr($msg, "[{"), '"askPrice":'), ',"askSize"', true)) != false and str_replace('"bidPrice":', "", strstr(strstr(strstr($msg, "[{"), '"bidPrice":'), ',"askPrice"', true)) != false){
$askPrice = str_replace('"askPrice":', "", strstr(strstr(strstr($msg, "[{"), '"askPrice":'), ',"askSize"', true));
$bidPrice = str_replace('"bidPrice":', "", strstr(strstr(strstr($msg, "[{"), '"bidPrice":'), ',"askPrice"', true));
echo "\r";
echo " ";
echo "\r";
echo "bidPrice={$bidPrice} | askPrice={$askPrice}";
}
});
$conn->send('{"op": "subscribe", "args": ["quote:XBTUSD"]}');
}, function ($e) {
echo "Could not connect: {$e->getMessage()}\n";
});