title: Reading messages from RabbitMQ with php-amqlib is not working
body: <p>I'm working on a client-server communication with PHP and RabbitMQ, using <a href="https://github.com/php-amqplib/php-amqplib" rel="nofollow noreferrer">php-amqplib</a>.</p>
  
  <p>I have a producer script that looks like working fine, but my consumer does not receive anything. </p>
  
  <p>I checked the entries in queue with <code>sudo rabbitmqctl list_queues</code> and after each time I run the producer, the counter increments in it. </p>
  
  <p>My consumer starts without any PHP errors and looks like waiting for messages.
  What not looks good it runs the callback script once with empty incoming message once at start - and than does not do anything. </p>
  
  <pre><code>php consumer.php 
  string(47) " [*] Waiting for messages. To exit press CTRL+C"
  string(1) "
  "
  string(10) "Received: "
  </code></pre>
  
  <p>Here are my codes:</p>
  
  <p>producer.php</p>
  
  <pre><code>public function sendDataToRabbitMQ()
  {
      $id = $_POST['id'];
      $ipAddress = $_POST['ip'];
      $date = date("Y-m-d h:i:s");
      $status = false;
  
      $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest'); //host: RABBITMQ_HOST
      $channel = $connection-&gt;channel();
  
      $channel-&gt;queue_declare('first_queue', false, true, false, false);
  
      if(is_array($argv)) {
          $data = implode(' ', array_slice($argv, 1));
      }
  
      if (empty($data)) {
          $data = "$ipAddress,$id";
      }
  
      $msg = new AMQPMessage($data, array('delivery_mode' =&gt; AMQPMessage::DELIVERY_MODE_PERSISTENT));
  
      $channel-&gt;basic_publish($msg, '', 'first_queue');
  
      echo " [x] Sent data:", "\n", $data, "\n";
  
      $channel-&gt;close();
      $connection-&gt;close();
  
      return $result;
  }
  </code></pre>
  
  <p>(changed host name constant to localhost for testing purposes)</p>
  
  <p>consumer.php</p>
  
  <pre><code>&lt;?php
  
  require_once '../vendor/autoload.php';
  
  use PhpAmqpLib\Connection\AMQPStreamConnection;
  
  class Consumer
  {
      private $token;
  
      private function getQueue()
      {
          $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
          $channel = $connection-&gt;channel();
  
          $channel-&gt;queue_declare('ban_queue', false, true, false, false);
  
          var_dump(' [*] Waiting for messages. To exit press CTRL+C', "\n");
  
          $callback = function($msg) {
  
              $message = explode(',', $msg-&gt;body);
  
              var_dump('Received: '.$message[0]);
  
              $msg-&gt;delivery_info['channel']-&gt;basic_ack($msg-&gt;delivery_info['delivery_tag']);
          };
  
          $channel-&gt;basic_qos(null, 1, null);
          $channel-&gt;basic_consume('first_queue', '', false, false, false, false, $callback);
          while (count($channel-&gt;callbacks)) {
              $channel-&gt;wait();
          }
          $channel-&gt;close();
          $connection-&gt;close();
      }
  
      public function processResult()
      {
          $this-&gt;getQueue();
      }
  
  }
  
  $consumer = new Consumer();
  $consumer-&gt;processResult();
  </code></pre>
  
  <p>Why is it not working? I found the rabbitmq/php-amqplib tutorials and documentation pretty useless and completely struck on this issue for more than a half day now. Any help is appreciated. </p>
  
  <p>UPDATE 1</p>
  
  <p>I also checked this <a href="https://stackoverflow.com/questions/42933465/php-amqp-channel-callback-loop">QA</a> from this site, and my code is coherent to it. </p>