title: How to send a message to ReactPHP/Amp/Swoole/etc. from PHP-FPM?
body: <p>I'm thinking about making a worker script to handle async tasks on my server, using a framework such as ReactPHP, Amp or Swoole that would be running permanently as a service (I haven't made my choice between these frameworks yet, so solutions involving any of these are helpful).</p>
  
  <p>My web endpoints would still be managed by Apache + PHP-FPM as normal, and I want them to be able to send messages to the permanently running script to make it aware that an async job is ready to be processed ASAP.</p>
  
  <p>Pseudo-code from a web endpoint:</p>
  
  <pre class="lang-php prettyprint-override"><code>$pdo-&gt;exec('INSERT INTO Jobs VALUES (...)');
  $jobId = $pdo-&gt;lastInsertId();
  
  notify_new_job_to_worker($jobId); // how?
  </code></pre>
  
  <p><strong>How do you typically handle communication from PHP-FPM to the permanently running script in any of these frameworks?</strong> Do you set up a TCP / Unix Socket server and implement your own messaging protocol, or are there ready-made solutions to tackle this problem?</p>
  
  <hr>
  
  <p><sub><em>Note: In case you're wondering, I'm not planning to use a third-party message queue software, as I want async jobs to be stored as part of the database transaction (either the whole transaction is successful, <strong>including</strong> committing the pending job, or the whole transaction is discarded). This is my guarantee that no jobs will be lost. If, worst case scenario, the message cannot be sent to the running service, missed jobs may still be retrieved from the database at a later time.</em></sub></p>