V
V
Vitaly B2018-06-24 16:18:52
PHP
Vitaly B, 2018-06-24 16:18:52

PHP client for Websocket(socket.io) over wss (SSl from letsencrypt)?

Task : using PHP, connect to a socket via wss and transfer data. If globally, then we need a real-time notification system for site users. Backend in PHP.
Prerequisites : connection using a certificate from LetsEncrypt
Server : Ubuntu 16.04, PHP 7, Websocket server (socket.io or ws), OpenSSL enabled, LetsEncrypt .crt/.ca/.pem files
There are no questions or problems with the Websocket server and the client's wss connection to js. And here with implementation of the client on php a problem. If I start the server without SSL, then I connect to php using stream_socket_client or fsockopen. I have not tried any libraries yet, but googling has shown that the issue of connecting via wss to PHP is quite frequent. And there was no complete answer. The only crutches that I saw about this topic are proxying. Help advice where to dig. Or is it worth trying to get acquainted with Elephant and Ratchet (and there are working examples for wss)?
I tried on PHP stream_context_create + stream_socket_client with various options for parameters, but I already got confused in them. Now I get either $errno = 0 or Bad Request 400.

$cert = 'путь к сертификату .ca или .pem';
$context = stream_context_create([ 'ssl' => [
         'allow_self_signed' => false,
          'verify_peer'   => true,
          'cafile'        => $cert,
          'local_cert'        => 'путь к сертификату .crt',
        'verify_depth'  => 3,
          'CN_match'      => 'домен',
          'disable_compression' => true,
          'SNI_enabled'         => true,
          'ciphers'             => $ciphers,
          'SNI_server_name' => 'домен'
          'capture_peer_cert' => true,
          'cafile' => $cert,
        'peer_name' => 'домен',
        'ciphers' => $ciphers,
        'disable_compression' => true,
]]);

$socket = stream_socket_client("ssl://домен:4444/web", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Troodi Larson, 2018-06-24
@troodi

https://github.com/walkor/Workerman
Used this package, everything works fine. With a let certificate.

A
Alexander Alexandrovich, 2018-06-24
@tatu

Ratchet has a separate Pawl client , but the issue with SSL will have to be resolved regardless of the packages chosen.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question