title: Set up a worker in Yii2-Heroku
body: <p>I have a controller action for accepting the bulk user data, process data and then present the result. Since it is a tedious process, I am trying to assign the same to a worker and later present the results.</p>
  
  <p>I need help with setting up the worker here.</p>
  
  <p>My current procfile is </p>
  
  <pre><code> web: vendor/bin/heroku-php-apache2
   worker: php yii hello/process
  </code></pre>
  
  <p>And I am testing it by running </p>
  
  <pre><code>public function actionTest(){
      $config  = require(__DIR__ . '/../config/console.php');
      $console = new \yii\console\Application($config);
      $console-&gt;runAction("hello/send");
  }
  </code></pre>
  
  <p>Send Command</p>
  
  <pre><code>public function actionSend($message = 'hello world')
  {
      $conn = $this-&gt;connection;
      $ch = $conn-&gt;channel();
  
      $exchange = 'amq.direct';
      $queue = 'basic_get_queue';
      $ch-&gt;queue_declare($queue, false, true, false, false);
      //$ch-&gt;exchange_declare($exchange, 'direct', true, true, false);
      //$ch-&gt;queue_bind($queue, $exchange);
  
      $msg_body = $message;
      $msg = new AMQPMessage($msg_body, array('content_type' =&gt; 'text/plain', 'delivery_mode' =&gt; 2));
      $ch-&gt;basic_publish($msg,'', $queue);
  
      /*      
      $retrived_msg = $ch-&gt;basic_get($queue);
      var_dump($retrived_msg-&gt;body);
      $ch-&gt;basic_ack($retrived_msg-&gt;delivery_info['delivery_tag']); */
  
      $ch-&gt;close();
      $conn-&gt;close();
  
  }
  </code></pre>
  
  <p>Process Command</p>
  
  <pre><code>public function actionProcess(){
      $conn = $this-&gt;connection;
      $ch = $conn-&gt;channel(); 
      $queue = 'basic_get_queue';
      $ch-&gt;queue_declare($queue, false, true, false, false);
  
      //$retrived_msg = $ch-&gt;basic_get($queue);
      $callback = function($msg) {
          $msg-&gt;delivery_info['channel']-&gt;basic_ack($msg-&gt;delivery_info['delivery_tag']);         
          echo $msg-&gt;body;
      };
      $ch-&gt;basic_qos(null, 1, null);
      $ch-&gt;basic_consume($queue, '', false, false, false, false, $callback);
      // loop over incoming messages
      while(count($ch-&gt;callbacks)) {
          $ch-&gt;wait();
      }
  
      $ch-&gt;close();
      $conn-&gt;close();
  }
  </code></pre>
  
  <p>But it is not triggering the worker!</p>
  
  <p>I opened two terminals and tried and I could get the message echoed in the process command window.</p>
  
  <p>Upon deploying, I could see the worker up and running </p>
  
  <p><code>2017-03-13T10:25:24.114552+00:00 heroku[worker.1]: Starting process with command 'php yii hello/process'</code></p>
  
  <p><code>2017-03-13T10:25:24.783227+00:00 heroku[worker.1]: State changed from starting to up</code></p>
  
  <p>But worker is not triggering when I run the <code>send command</code> even from the terminal.</p>
  
  <p>Please help!</p>