Simplified server code:

$ip="127.0.0.1"; $port="8099"; $pem_passphrase = "wdwedwdw"; $pem_file = "filename.pem"; $pem_dn = array( "countryName" => "UK", "stateOrProvinceName" => "Herts", "localityName" => "St. Albans", "organizationName" => "Your Company", "organizationalUnitName" => "Your Department", "commonName" => "Your full hostname", "emailAddress" => "email@example.com" ); echo "Creating SSL Cert\n"; createSSLCert($pem_file, $pem_passphrase, $pem_dn); echo "Listening to {$ip}:{$port} for connections\n"; $socket = setupTcpStreamServer($pem_file, $pem_passphrase, $ip, $port); if (!$socket) {die("$errstr ($errno)\n");} function setupTcpStreamServer($pem_file, $pem_passphrase, $ip, $port) { $context = stream_context_create(); stream_context_set_option($context, 'ssl', 'local_cert', $pem_file); // Our SSL Cert in PEM format stream_context_set_option($context, 'ssl', 'passphrase', $pem_passphrase); // Private key Password stream_context_set_option($context, 'ssl', 'allow_self_signed', true); stream_context_set_option($context, 'ssl', 'verify_peer', false); $socket = stream_socket_server("ssl://{$ip}:{$port}", $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context); return $socket; } function createSSLCert($pem_file, $pem_passphrase, $pem_dn) { $privkey = openssl_pkey_new(); $cert = openssl_csr_new($pem_dn, $privkey); $cert = openssl_csr_sign($cert, null, $privkey, 365); $pem = array(); openssl_x509_export($cert, $pem[0]); openssl_pkey_export($privkey, $pem[1], $pem_passphrase); $pem = implode($pem); file_put_contents($pem_file, $pem); chmod($pem_file, 0600); } if (!$socket) {die("$errstr ($errno)\n");} echo "--демон чат сервера стартовал\n"; $connects = array(); while (true) { //формируем массив прослушиваемых сокетов: $read = $connects; $read []= $socket; $write = $except = null; if (!stream_select($read, $write, $except, null)) {break;} if (in_array($socket, $read)) { $connect = stream_socket_accept($socket, -1); if ($connect==true){ $info = handshakeSocket($connect); if ($info==true){ $connects[] = $connect;//добавляем его в список необходимых для обработки onOpen($connect, $info);//вызываем пользовательский сценарий }; }; unset($read[ array_search($socket, $read) ]); } foreach($read as $connect) {//обрабатываем все соединения $data = fread($connect, 100000); if (!$data) { //соединение было закрыто fclose($connect); unset($connects[ array_search($connect, $connects) ]); onClose($connect);//вызываем пользовательский сценарий continue; } onMessage($connect, $data,$info);//вызываем пользовательский сценарий } } fclose($server); 

The server starts up normally, but from the browser, if you start it in the console:

 zz=new WebSocket("wss://127.0.0.1:8099") 

Error: WebSocket connection to 'wss: //127.0.0.1: 8099 /' failed: Error in connection establishment: net :: ERR_SSL_SERVER_CERT_BAD_FORMAT

  • so you have ssl wrong on the server. Maybe not installed at all. See php logs on server for debug. - Naumov
  • In the logs (well, which spits out the script in the terminal), there is nothing. Open SSL is installed. The certificate file is generated. - Gribov Pavel
  • in php-cli interpreter logs or fpm - Naumov
  • The script runs php <script.php> in the terminal. All errors, if any, should fall into the terminal. They are not. OS: Ubuntu 15.4 - Pavel Gribov
  • After adding a node to the exceptions in firefox, $ connect = stream_socket_accept ($ socket, -1); Began to produce an error: error: 14094412: SSL routines: SSL3_READ_BYTES: sslv3 alert bad certificate - Gribov Pavel

0