title: HTML5 game <-> server
body: <p>I have:</p>
  
  <ol>
  <li><p>PHP Socket Server</p></li>
  <li><p>PHP Pages to handle communication with server &amp; db</p></li>
  <li><p>Client .php page, which uses javascript/canvas to display &amp; interact with a game.</p></li>
  </ol>
  
  <p>What I want is for the user to connect and authenticate using the PHP pages which will initiate a socket connection to the server. Based on the information from that socket some chat info and events might be triggered to load data into client php page.</p>
  
  <p>What is the right way to handle this. In all instances that I've ajax in before, the user triggers the event, not the server and javascript waits around for the php page's response.</p>
  
  <p>What piece of php code from the php socket lets me send messages to the canvas elements?</p>
  
  <p>Here's an example as the above is probably not very illuminating:</p>
  
  <p>IE:
  PHP reads off of its socket connection <code>{"name":"msg","from":"user1","time":12345,"msg","hello world"}</code></p>
  
  <p>At this point what does PHP do?** So that ...</p>
  
  <p>The client has a div with <code>"id='Incoming'"</code></p>
  
  <p>I want to launch the following javascript:</p>
  
  <pre><code>function handleMessage(msgObj) {
    var cText = document.getElementById("Incoming").innerHTML;
    cText += "(" + msgObj.time + ")" + msgObj.from + " says: " + msgObj.msg +"&lt;br/&gt;";
    document.getElementById("Incoming").innerHTML = cText;
  }
  </code></pre>
  
  <p>I guess I'm trying to figure out how a client's web page is supposed to talk back to the php sockets...</p>
  
  <p>Is this possible or do I need to make a client in flash, java, etc?</p>