简体   繁体   中英

Create PHP WebSocket with SSL

I have a websocket chat on my website and I recently added SSL certificate to my website. When I open my website with http , chat works. When I open it with https it's not working. I am using javascript as client for my chat with ws:// protocol. I changed that protocol to wss:// because of SSL encryption on my page, but it won't work that way. Here's part of my PHP server code that creates the socket:

$host = 'localhost'; 
$port = '9000'; 
$null = NULL;

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);

socket_bind($socket, 0, $port);

socket_listen($socket);

$clients = array($socket);

how do you add a certificate to a php socket?

using a different function call.

http://php.net/manual/en/function.stream-socket-client.php

and setting the correct socket options

http://php.net/manual/en/context.ssl.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM