If you are looking for something quick and dirty @joeblog example is the quickest (copied from his link above):
Write this in pong.pl
:
:- use_module(library(http/websocket)).
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- http_handler(root(pong), http_upgrade_to_websocket(pong_handler, []), [spawn([])]).
server(Port) :-
http_server(http_dispatch, [port(Port)]).
pong_handler(Request) :-
ws_receive(Request, Message),
debug(websocket, "Got ~p~n", [Message]),
format("Received ~p~n", [Message]),
( Message.opcode == close
-> ws_send(Request, close(1000, "Bye")),
format("Pong finished~n")
; ws_send(Request, text("Pong")),
format("Sent Pong~n"),
pong_handler(Request)
).
Now in a terminal run:
$ swipl -g 'server(8001)' pong.pl
while running this in another terminal:
$ websocat ws://127.0.0.1:8001/pong 09:26:51 ✔ 0
hello
Pong
hi
Pong
goodbye
Pong
You’ll get this output:
$ swipl -g 'server(8001)' t.pl
% Started server at http://localhost:8001/
1 ?- Received websocket{data:"hello\n",format:string,opcode:text}
Sent Pong
Received websocket{data:"hi\n",format:string,opcode:text}
Sent Pong
Received websocket{data:"goodbye\n",format:string,opcode:text}
Sent Pong
Received websocket{code:1000,data:"",format:string,opcode:close}
Pong finished
From there you can easily see how to connect with the server using php and websockets.