title: What's the easiest way to do inter-process communication in PHP?
body: <p>I have written a program in PHP that continually updates a database. I would like it to <strong>spit out data as it runs, so that other processes can read it</strong> and do stuff with it.</p>
  
  <p>Here's what I mean in a diagram:</p>
  
  <p><a href="https://i.stack.imgur.com/pAHk8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pAHk8.png" alt=""></a></p>
  
  <p>I realize that I'm looking for some sort of <em>inter-process communication</em> (IPC) to achieve this, but I'm not sure what the <strong>easiest/simplest way to do it is in PHP</strong>.</p>
  
  <p>Here are two possible solutions I've come up with:</p>
  
  <p><strong>1. Turn the Main Process in to a Unix Socket server.</strong></p>
  
  <p>I could add some socket code to the Main Process to turn it in to a Unix Socket server, handling connections and writing to the socket as it runs. Other processes can then connect and read data from the socket:</p>
  
  <p><a href="https://i.stack.imgur.com/pg8BJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pg8BJ.png" alt=""></a></p>
  
  <p>However, this means that the Main Program will have to deal with being both a socket server along with doing its primary job. Furthermore, PHP doesn't support threading out of the box, which makes handling multiple connections a little trickier, and so the whole program will become much more complex.</p>
  
  <p>In all, this doesn't seem like the simplest solution, especially for a program written in PHP (unfortunately).</p>
  
  <p><strong>2. Create a separate Unix Socket server.</strong></p>
  
  <p>Alternatively, I could write a separate Unix Socket server program that the Main Process can write to, and it will relay all writes to any other process that connects to it:</p>
  
  <p><a href="https://i.stack.imgur.com/gKUZY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gKUZY.png" alt=""></a></p>
  
  <p>This has the benefit of separating the socket serving responsibilities from the Main Process. It would also make the connection handling much simpler as I could write it in a language that is better suited to being a socket server.</p>
  
  <p>But on the other hand, it does mean that I will need to write and run an additional program to help me handle the inter-process communication.</p>
  
  <p><strong>Is there a simpler solution?</strong></p>
  
  <p>Option 2 is my preferred solution so far, but <strong>is there some alternative method that I may be missing here?</strong></p>
  
  <p>Again, I just want an existing PHP process to spit some data out as it runs, and for other processes to be able to read from it.</p>
  
  <p>What are some simple solutions for this kind of interprocess communication?</p>