PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Creating your own adapter

Zend_Queue will accept any adapter that implements Zend_Queue_Adapter_AdapterAbstract. You can create your own adapter by extending one of the existing adapters, or the abstract class Zend_Queue_Adapter_AdapterAbstract. I suggest reviewing Zend_Queue_Adapter_Array as this adapter is the easiest to conceptualize.

<?php
class Custom_DbForUpdate extends Zend_Queue_Adapter_Db
{
    
/**
     * @see code in tests/Zend/Queue/Custom/DbForUpdate.php
     *
     * Custom_DbForUpdate uses the SELECT ... FOR UPDATE to find it's rows.
     * this is more likely to produce the wanted rows than the existing code.
     *
     * However, not all databases have SELECT ... FOR UPDATE as a feature.
     *
     * Note: this was later converted to be an option for Zend_Queue_Adapter_Db
     *
     * This code still serves as a good example.
     */
}

$options = array(
    
'name'          => 'queue1',
    
'driverOptions' => array(
        
'host'      => '127.0.0.1',
        
'port'      => '3306',
        
'username'  => 'queue',
        
'password'  => 'queue',
        
'dbname'    => 'queue',
        
'type'      => 'pdo_mysql'
    
)
);

$adapter = new Custom_DbForUpdate($options);
$queue = new Zend_Queue($adapter$options);

You can also change the adapter on the fly as well.

<?php
$adapter 
= new MyCustom_Adapter($options);
$queue   = new Zend_Queue($options);
$queue->setAdapter($adapter);
echo 
"Adapter: "get_class($queue->getAdapter()), "\n";

or

<?php
$options 
= array(
    
'name'           => 'queue1',
    
'namespace'      => 'Custom',
    
'driverOptions'  => array(
        
'host'       => '127.0.0.1',
        
'port'       => '3306',
        
'username'   => 'queue',
        
'password'   => 'queue',
        
'dbname'     => 'queue',
        
'type'       => 'pdo_mysql'
    
)
);
$queue = new Zend_Queue('DbForUpdate'$config); // loads Custom_DbForUpdate

Zend Framework