title: php-amqplib - Fatal error: Call to a member function basic_get() on resource
body: <p>Using a queue system for handling jobs.  We have a cron run once every morning at 1am and it publishes all of our required API calls.  We have another consumer cron that runs every five minutes that addresses the requests in the queue.</p>
  
  <p>We are in a shared environment and scripts called via cron are terminated after 15 minutes.  Therefore to protect ourselves we gracefully terminate our script after 9 minutes.</p>
  
  <p>Nearly all of our API calls are running with the exception of (2), which we are trying to figure out why.  When we run them manually via the same script they work perfectly.  Strange.  Only fail when run via cron with all of the other requests.</p>
  
  <p>In any case the nightly logs show the following Fatal Error occurring multiple times.  Maybe this is the culprit.  Unable to determine what is causing this.  If I manually kill the AMQP connections I get a different error so I know $ch and $conn are not being overridden somewhere in one of the API calls.</p>
  
  <p>Fatal error: Call to a member function basic_get() on resource in /........../consume_requests.php on line 116</p>
  
  <p>Below is our initialization of phpamqplib.  Any help would be appreciated.</p>
  
  <pre><code>require '/vendors/php-amqplib/autoload.php';
  use PhpAmqpLib\Connection\AMQPStreamConnection;
  use PhpAmqpLib\Message\AMQPMessage;
  
  try {
      $queue = 'my_queue';
      $url = parse_url(URL);
      $conn = new AMQPStreamConnection(HOST, 5555, USER, PASS, PATH, 1));
      $ch = $conn-&gt;channel();
      $ch-&gt;queue_declare($queue, false, true, false, false);
      $ch-&gt;exchange_declare(EXCHANGE, 'direct', true, true, false);
      $ch-&gt;queue_bind($queue, EXCHANGE,$queue);
  } catch(Exception $e) {
      echo $e-&gt;getMessage();
  }
  
  
  while($message_receipt = $ch-&gt;basic_get($queue)) {  //line 116
  </code></pre>