title: PHP RabbitMQ setTimeout or other option to stop waiting for queue
body: <p>I'm required to create a simple queue manager to pass a number from a sender to a consumer. Hello World tutorial provided by RabbitMQ covers almost 70% of it.</p>
  
  <p>But I need to change the queue to not to forever waiting for incoming messages. Or stop waiting after certain amount of messages. I read and tried few solutions from other post, but it doesn't work.</p>
  
  <p><a href="https://stackoverflow.com/questions/15487657/rabbitmq-amqpconsume">rabbitmq AMQP::consume()</a> - undefined method. there's another method, wait_frame but it is protected.</p>
  
  <p>and other post is in python which I dont understand.</p>
  
  <pre><code>&lt;?php
  
  require_once __DIR__ . '/vendor/autoload.php';
  require 'config.php';
  use PhpAmqpLib\Connection\AMQPStreamConnection;
  
  function recieveQueue($queueName){
      $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
  
      // try{
      //  $connection-&gt;wait_frame(10);
      // }catch(AMQPConnectionException $e){
      //  echo "asdasd";
      // }
  
      $channel = $connection-&gt;channel();
  
      $channel-&gt;queue_declare($queueName, false, false, false, false);
  
      echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
  
      $callback = function($msg) {
          echo " [x] Received ", $msg-&gt;body, "\n";
  
      };
  
      // $tag = uniqid() . microtime(true);
      // $queue-&gt;consume($callback, $flags, $tag);
  
      $channel-&gt;basic_consume($queueName, '', false, true, false, false, $callback);
  
      // $channel-&gt;cancel($tag);
  
      while(count($channel-&gt;callbacks)) {
          $channel-&gt;wait();
      }
  
      echo "\nfinish";
  }
  
  recieveQueue('vtiger');
  
  ?&gt;
  </code></pre>