php websocket at BINANCE FUTURES does not work

In the example below in BINANCE SPOT it works:

<?php $sock=stream_socket_client("tls://stream.binance.com:9443",$error,$errnum,30,STREAM_CLIENT_CONNECT,stream_context_create(null)); if (!$sock) { echo "[$errnum] $error" . PHP_EOL; } else { echo 'Conected!'; }

But in the example below in BINANCE FUTURES it doesn’t work:

<?php $sock=stream_socket_client("tls://fstream.binance.com",$error,$errnum,30,STREAM_CLIE>NT_CONNECT,stream_context_create(null)); if (!$sock) { echo "[$errnum] $error" . PHP_EOL; } else { echo 'Conected!'; }

Why?

Thanks in advance.

Hi. Please provide the final url for the futures part. From here, it’s hard to know the value of those variables and what are done by the methods.

It works (SPOT)

<?php $sock=stream_socket_client("tls://stream.binance.com:9443",$error,$errnum,30,STREAM_CLIENT_CONNECT,stream_context_create(null)); if (!$sock) { echo "[$errnum] $error" . PHP_EOL; } else { echo "Connected - Do NOT get rekt!" . PHP_EOL; fwrite($sock, "GET /stream?streams=btcusdt@kline_1m HTTP/1.1\r\nHost: >stream.binance.com:9443\r\nAccept: */*\r\nConnection: Upgrade\r\nUpgrade: >websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: ".rand(0,999)."\r\n\r\n"); while (!feof($sock)) { var_dump(explode(",",fgets($sock, 512))); } }

This below doesn’t work(FUTURES)

$sock=stream_socket_client(“tls://fstream.binance.com”,$error,$errnum,30,STREAM_CLIENT_CONNECT,stream_context_create(null));
if (!$sock) {
echo “[$errnum] $error” . PHP_EOL;
} else {
echo “Connected - Do NOT get rekt!” . PHP_EOL;
fwrite($sock, “GET /stream?streams=btcusdt@kline_1m HTTP/1.1\r\nHost: fstream.binance.com\r\nAccept: /\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: “.rand(0,999).”\r\n\r\n”);
while (!feof($sock)) {
var_dump(explode(",",fgets($sock, 512)));
}
}