title: MySQL query sent to beanstalk queue on opencart
body: <p>I am currently developing a website based on open cart and found myself in the position where I need some MySQL queries to run in background due to heavy load.</p>
  
  <p>Basically I need to update my product table with new prices. Since my product table has over 2 million entries, queries started to work slowly.</p>
  
  <p>I have installed pheanstalk client, and I have the latest opencart version.
  Here is my code:</p>
  
  <pre><code>require_once('pheanstalk_init.php');
  
  $pheanstalk = new Pheanstalk_Pheanstalk('127.0.0.1');
  
  $pheanstalk
   -&gt;useTube('mytube')
   -&gt;put($this-&gt;model_catalog_trade_markup-&gt;editTradeMarkup($this-&gt;request- &gt;get['trade_markup_id'],$this-&gt;request-&gt;post));
  
  $job = $pheanstalk
  -&gt;watch('mytube')
  -&gt;ignore('default')
  -&gt;reserve();
  
  $pheanstalk-&gt;delete($job);
  
  $this-&gt;redirect($this-&gt;url-&gt;link('catalog/trade_markup', 'token=' . $this-&gt;session-&gt;data['token'], 'SSL'));
  </code></pre>
  
  <p>My problem is that the query runs as normal (>30sec) and is not being sent to queue or it waits for the results to send them through. That is my concern, and I'm pretty sure I'm lost:) as I dont understand how is it working.</p>
  
  <p>Any info on how can I check the results or what am I doing wrong here?</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Here is the model: </p>
  
  <pre><code>public function editTradeMarkup($markup_id, $data){
      // TradeMarkup General Data
      $sql = "
      UPDATE `".DB_PREFIX."trade_mark` 
          SET name = '". $this-&gt;db-&gt;escape($data['name']) ."', type='". $data['type'] . "', amount='". $data['amount'] . "',
          conditions='"  .    serialize(array(
              "manufacturers"         =&gt; isset($data['manufacturers']) ? $data['manufacturers'] : '',
              "from_price"            =&gt; isset($data['from_price']) ? $data['from_price'] : '',
              "to_price"                  =&gt; isset($data['to_price']) ? $data['to_price'] : '',
              "universal"             =&gt; isset($data['universal']) ? $data['universal'] : ''
          )) . "' WHERE trade_mark_id = " . (int)$markup_id
      ;
      $query = $this-&gt;db-&gt;query($sql);
  
      $products = $this-&gt;getProducts($data);
      $in = array();
  
      $this-&gt;db-&gt;query("DELETE FROM `".DB_PREFIX."product_trade_mark` WHERE trade_mark_id = " . (int)$markup_id);
  
      foreach ($products as $product) {
          $in[] = $product['product_id'];
  
          if($data['type'] == 'procent'){
              $price = $product['list_price'] + ($product['list_price'] * $data['amount'] / 100);
          }else{
              $price = $product['list_price'] + $data['amount'];
          }
  
  
  
          $this-&gt;db-&gt;query("INSERT INTO `".DB_PREFIX."product_trade_mark` 
              SET trade_mark_id = '" . $markup_id . "',product_id = '" . $product['product_id'] . "', price='" . $price . "', priority = '1'");
      }
  
      if(empty($in)) return;
      $in = '(' . implode(',', $in) . ')';
      $this-&gt;db-&gt;query("UPDATE `".DB_PREFIX."product` p SET price = (SELECT price FROM product_trade_mark ptm WHERE p.product_id = ptm.product_id ORDER BY priority DESC LIMIT 1) WHERE product_id IN " . $in . "");
  
  }
  </code></pre>