WebSocket with server on php



  • Good night, trying to figure out the webs, that's the server part on the php. It's easy with the client:

    <script>
        ws = new WebSocket("ws://site.com/demo");
        ws.onopen = function() { alert("Connection opened...") };
        ws.onclose = function() { alert("Connection closed...") };
        ws.onmessage = function(evt) { $("#msg").append("<p>"+evt.data+"</p>"); }; 
    </script>
    

    Here's the server... He's rereading a bunch of chabra posts, here, and not just. But I can't figure out what the phpDeamon or Ratchet is for, and where are they needed? And in the shadows for me, there's a way to put them on a real hosting, there's a conversation about putting them on local servers like denwer or openserver. Enlighten the please.



  • Ratchet, phpDaemon, Workerman, etc. are libraries that help to create a server (in your case, Websocket) in a few dozen lines, simply by using the library &apos; s interface (onClose, onOpen, onMessage, onError) and by working with functions that are written before you.

    Afterwards, you launch a PHP scrupt, which is a demon, and he's listening to the port for the connection and giving the customers the answer on the actual interface.

    No, of course you can write it yourself and use your own library instead of a few lines, but you're going to have a lot of time, because you need to figure out the subtle of the protocol, the handshake, the transfer of titles, the sending of messages, the writing of different functions, the processing of customers, the time to make a mess... It's all written before you.

    What do you mean by a real hosting? If shared, it's not likely (because of restrictions, but it's better to specify at the host, it's gonna work on the VPS.

    Example of the Rachet server. https://github.com/ratchetphp/Ratchet


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2