PhpRiot
Follow phpriot on Twitter
Sponsored Link
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
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

AMQPQueue::ack

(No version information available, might only be in SVN)

AMQPQueue::ackAcknowledge the receipt of a message

Description

public bool AMQPQueue::ack ( int $delivery_tag [, int $flags = NULL ] )

This method allows the acknowledgement of a message that is retrieved with the AMQP_NOACK flag through AMQPQueue::get or AMQPQueue::consume

Parameters

delivery_tag

The message delivery tag of which to acknowledge receipt.

flags

The only valid flag that can be passed is AMQP_MULTIPLE.

Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example #1 AMQPQueue::ack example with AMQPQueue::get

<?php

/* Create a connection using all default credentials: */
$connection = new AMQPConnection();
$connection->connect();

/* create a queue object */
$queue = new AMQPQueue($connection);

//declare the queue
$queue->declare('myqueue');

//get the next message, but don't mark it as delivered
$message $queue->get(AMQP_NOACK);

echo 
$message['msg'];

//acknowledge the message as received
$queue->ack($message['delivery_tag']);

?>

Example #2 AMQPQueue::ack example with AMQPQueue::consume

<?php

/* Create a connection using all default credentials: */
$connection = new AMQPConnection();
$connection->connect();

/* create a queue object */
$queue = new AMQPQueue($connection);

//declare the queue
$queue->declare('myqueue');

$options = array(
    
'min' => 1,
    
'max' => 10,
    
'ack' => false
);

//get the messages, but don't mark them as delivered
$messages $queue->consume($options);

foreach (
$messages as $message) {
    echo 
$message['message_body'];
    
//acknowledge the message as received
    
$queue->ack($message['delivery_tag']);
}

?>

PHP Manual