facebook twitter hatena line email

Php/zend framework/zend queue/dbモデル

提供: 初心者エンジニアの簡易メモ
2016年3月19日 (土) 18:57時点におけるAdmin (トーク | 投稿記録)による版 (ページの作成:「-batch/sample.php require_once APPLICATION_PATH . '/models/que/TestsQue.php'; $que = new TestsQue(); $messages = $que->receive(5); foreach ($messages as $i => $messag...」)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

-batch/sample.php

require_once APPLICATION_PATH . '/models/que/TestsQue.php';
$que = new TestsQue();
$messages = $que->receive(5);
foreach ($messages as $i => $message) {
   echo $message->body, "\n";
   $que->deleteMessage($message);
}
$que->send("My Test Message");

-models/que/AbstractQue.php

abstract class AbstractQue extends Zend_Queue
{
 protected $_name = "";
 public function __construct()
 {
   if (!$this->_name) return;
   $config = ConfigModel::getInstance(APPLICATION_PATH . '/configs/db.ini', APPLICATION_ENV);
   $driverOptions = $config->default->params->toArray();
   $driverOptions['type'] = $config->default->adapter;
   $options = array(
     'driverOptions' => $driverOptions,
     'options' => array(
       Zend_Db_Select::FOR_UPDATE => true
     ),
     'name' => $this->_name,
   );
   parent::__construct('Db', $options);
 }
 public function count()
 {
   return count($this);
 }
}

-models/que/TestsQue.php

require_once __DIR__ . '/AbstractQue.php';
class TestsQue extends AbstractQue
{
  protected $_name = "queue1";
}