Textalk / websocket-php

WebSocket client and server in PHP
Other
926 stars 255 forks source link

failed to connect wss #181

Open icooooler opened 1 year ago

icooooler commented 1 year ago
  $subscription = [
        'method' => 'SUBSCRIPTION',
        'params' => ['spot@public.deals.v3.api@BTCUSDT', 'spot@public.deals.v3.api@ETHUSDT'],
    ];

    $context = stream_context_create();
    stream_context_set_option($context, 'ssl', 'verify_peer', false);
    stream_context_set_option($context, 'ssl', 'verify_peer_name', false);

    $client = new Client('wss://wbs.mexc.com/ws', [
        'context' => $context, // Attach stream context created above
        'timeout' => 10
    ]);

    $client->text(json_encode($subscription));

    while (true) {

        $data = $client->receive();
        echo $data;
        sleep(1);
    }

I get error:Could not open socket to "wbs.mexc.com:443": stream_socket_client(): Failed to enable crypto (0).

so what should i do to fix it

sirn-se commented 1 year ago

@icooooler Your code works just fine for me, even without disabling peer verification. So the problem is probably SSL setup on the machine you're running the client on.