title: php: How to save the client socket (not closed), so a further script may retrieve it to send an answer?
body: <p>I have a client-server application, in which the server may require to send information back to clients.</p>
  
  <p>As the client-server pattern does not allow the server to "request" the client, there are 2 solutions:</p>
  
  <ul>
  <li>The client pull the server every few time (which is a bad solution)</li>
  <li>The client maintain an open socket with the server, that allow the server to send new information back when required.</li>
  </ul>
  
  <p>Currently, the client (Web app with JavaScript and Html/Css) open a streaming connection to the server (A C++ server) which may send information back to the client.</p>
  
  <p>I would like to implement a PHP version of this feature to allow low-cost hosting to work with my program (low-cost hosting usually does not provide access to install/run binaries).
  The idea is that the client make a request that establish the streaming socket, it save the socket and then, an other request may retrieve this socket and send new information through it.</p>
  
  <p>So, my question is:
  How to save an http socket in PHP, so a further request may retrieve it?</p>
  
  <ul>
  <li>How to finish the PHP script without closing the socket?</li>
  <li>How to save socket information?</li>
  <li>How to retrieve the socket from a new thread/request?</li>
  </ul>
  
  <p>I do not know even if that is possible, I read about pfsockopen, but it seem a bit different to what I need ( I may be wrong ).</p>
  
  <p><img src="https://i.stack.imgur.com/DbgAF.png" alt="enter image description here"></p>