title: Best practice when using websockets?
body: <p>I got a webapplication written in Laravel 4. This application makes use of Ratchet and to be more specific, it uses the package <a href="https://github.com/sidneywidmer/Latchet">Latchet</a>. As a sidenote I am using the following techniques :</p>
  
  <ul>
  <li><a href="http://autobahn.ws/js">AutoBahn JS</a></li>
  <li><a href="http://zeromq.org/">ZeroMQ</a></li>
  <li><a href="http://socketo.me/">Ratchet</a></li>
  </ul>
  
  <p>Now I got the following scenario:</p>
  
  <ul>
  <li>I have a slideshow which should receive updates through the websocket.</li>
  <li>The whole application is setup and I can publish new code changes from PHP to my websocket clients through ZeroMq.</li>
  <li><p>In my routes.php, I have the following code, so that a topic is registered correctly :</p>
  
  <pre><code>//routes.php
  // Setup a connection and register a topic where clients can connect to.
  Latchet::connection('Connection');
  Latchet::topic('PhotoStream/{client}', 'PhotoStreamController');
  </code></pre></li>
  <li><p>Then, I start the ratchet server.</p></li>
  </ul>
  
  <p><code>sudo php artisan latchet:listen</code></p>
  
  <p>When a photo gets uploaded, I can then run the following code to push updates to the clients that are listening to my topic (<code>PhotoStream/client1</code> in this case):</p>
  
  <pre><code>// Create the object, save it to db and then publish it to my websockets
  $photo = new Photo;
  $photo-&gt;location = 'path/to/file';
  $photo-&gt;save();
  // Publish it through my websocket clients. (push from server).
  Latchet::publish('PhotoStream/client1', array('msg' =&gt; $photo-&gt;toArray() ));
  </code></pre>
  
  <p>This code all works, but it is in case of an update. My question is as follows:</p>
  
  <p>How should I handle the initialisation of the client? </p>
  
  <ol>
  <li>Should I first render the page with plain old PHP and then initialize my websocket client which then receive further updates (if there are any)?.</li>
  <li>Or should I, when I register a new websocket client, give an extra parameter with the request so the server sends me the complete data through websockets?</li>
  </ol>
  
  <p>The latter of the two options seems the best option to me but I don't really know how to implement this in a good way.</p>