title: How can I keep an Amazon SQS PHP reciever script running forever?
body: <p>I've previously used Gearman along with supervisor to manage jobs.</p>
  
  <p>In this case we are using Amazon SQS which I have spent some time trying to get my head around.</p>
  
  <p>I have set up a separate micro instance from our main webserver to use as an Image processing server (purely for testing at the moment, it will be upgraded and become part of a cluster before this implementation goes live)</p>
  
  <p>On this micro instance I have installed PHP and ImageMagick in order to perform the image processing.</p>
  
  <p>I have also written a worker script which receives the messages from Amazon SQS.</p>
  
  <p>All works perfectly, however I need this script to run over and over again in order to continuously check for messages.</p>
  
  <p>I don't like the thought of running a continuous loop so have started to look at other methods with little success.</p>
  
  <p>So my question is what is generally considered the best practice way to do this?</p>
  
  <p>I am worried about memory since PHP wasn't really designed for this, therefore it feels like running the script for a while, then stopping and restarting it might be my best bet.</p>
  
  <p>I have experience using supervisor (to ensure that gearman workers kept running) and am wondering if I could simply use that to continuously execute the simple php script over and over? </p>
  
  <p>My thoughts are as follows:</p>
  
  <ul>
  <li>Set up SQS long polling so that the script checks for 20 seconds.</li>
  <li>Use a while loop with a 20 second sleep to keep this script running for say an hour at a time</li>
  <li>Have all this run through supervisor. When the hour is up and the loop is complete, allow the script to exit. </li>
  <li>Supervisor should then automatically restart it</li>
  </ul>
  
  <p>Does this sound viable? Is there a better way?  What is generally considered the best practice for receiving SQS messages in PHP?</p>
  
  <p>Thanks in advance</p>