Amazon SQS

Amazon Simple Queue Service (http://aws.amazon.com/sqs)

Version

2008.11.02

Copyright

2006-2008 LifeNexus Digital, Inc., and contributors.

License

Simplified BSD Licensehttp://opensource.org/licenses/bsd-license.php

See Also

Tarzanhttp://tarzan-aws.com
Amazon SQShttp://aws.amazon.com/sqs

Constants

SQS_DEFAULT_URL

Specify the default queue URL.

AmazonSQS

Container for all Amazon SQS-related methods.  Inherits additional methods from TarzanCore.

Extends

TarzanCore

Example Usage

require_once('tarzan.class.php');

// Instantiate a new AmazonSQS object using the settings from the config.inc.php file.
$sqs = new AmazonSQS();

// Instantiate a new AmazonSQS object using these specific settings.
$sqs = new AmazonSQS($key, $secret_key);

Functions

__construct()

public function __construct($key =  null,
$secret_key =  null)

The constructor

Access

public

Parameters

keystring (Optional) Your Amazon API Key.  If blank, it will look for the AWS_KEY constant.
secret_keystring (Optional) Your Amazon API Secret Key.  If blank, it will look for the AWS_SECRET_KEY constant.

Returns

boolean false if no valid values are set, otherwise true.

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/sqs/__construct.phps

create_queue()

public function create_queue($queue_name,  
$returnCurlHandle =  null)

Creates a new queue to store messages in.  You must provide a queue name that is unique within the scope of the queues you own.  The queue is assigned a queue URL; you must use this URL when performing actions on the queue.  When you create a queue, if a queue with the same name already exists, create_queue() returns the queue URL with an error indicating that the queue already exists.

Access

public

Parameters

queue_namestring (Required) The name of the queue to use for this action.  The queue name must be unique within the scope of all your queues.
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/Query_QueryCreateQueue.html
Example Usagehttp://tarzan-aws.com/docs/examples/sqs/create_queue.phps
Relateddelete_queue(), list_queues(), get_queue_attributes(), set_queue_attributes()

delete_queue()

public function delete_queue($queue_url,  
$returnCurlHandle =  null)

Deletes the queue specified by the queue URL.  This will delete the queue even if it’s not empty.

Access

public

Parameters

queue_urlstring (Required) The URL of the queue to perform the action on.
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/Query_QueryDeleteQueue.html
Example Usagehttp://tarzan-aws.com/docs/examples/sqs/delete_queue.phps
Relatedcreate_queue(), list_queues(), get_queue_attributes(), set_queue_attributes()

list_queues()

public function list_queues($queue_name_prefix =  null,
$returnCurlHandle =  null)

Returns a list of your queues.  A maximum 1000 queue URLs are returned.  If you specify a value for the optional <queue_name_prefix> parameter, only queues with a name beginning with the specified value are returned.

Access

public

Parameters

queue_name_prefixstring (Optional) String to use for filtering the list results.  Only those queues whose name begins with the specified string are returned.
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/Query_QueryListQueues.html
Example Usagehttp://tarzan-aws.com/docs/examples/sqs/list_queues.phps
Relatedcreate_queue(), delete_queue(), get_queue_attributes(), set_queue_attributes()

get_queue_attributes()

public function get_queue_attributes($queue_url,  
$returnCurlHandle =  null)

Gets one or all attributes of a queue.

Access

public

Parameters

queue_urlstring (Required) The URL of the queue to perform the action on.
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/Query_QueryGetQueueAttributes.html
Example Usagehttp://tarzan-aws.com/docs/examples/sqs/get_queue_attributes.phps
Relatedcreate_queue(), delete_queue(), list_queues(), set_queue_attributes()

set_queue_attributes()

public function set_queue_attributes($queue_url,  
$opt =  null)

Sets an attribute of a queue.  Currently, you can set only the <VisibilityTimeout> attribute for a queue.  See Visibility Timeout for more information.

Access

public

Parameters

queue_urlstring (Required) The URL of the queue to perform the action on.
optarray (Required) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

VisibilityTimeoutinteger (Optional) Must be an integer from 0 to 7200 (2 hours).
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/Query_QueryGetQueueAttributes.html
Example Usagehttp://tarzan-aws.com/docs/examples/sqs/set_queue_attributes.phps
Relatedcreate_queue(), delete_queue(), list_queues(), get_queue_attributes()

send_message()

public function send_message($queue_url,  
$message,  
$returnCurlHandle =  null)

Delivers a message to the specified queue.

Access

public

Parameters

queue_urlstring (Required) The URL of the queue to perform the action on.
messagestring (Required) Message size cannot exceed 8 KB.  Allowed Unicode characters (according to http://www.w3.org/TR/REC-xml/#charsets): #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF].
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/Query_QuerySendMessage.html
Example Usagehttp://tarzan-aws.com/docs/examples/sqs/send_message.phps
Relatedreceive_message(), delete_message()

receive_message()

public function receive_message($queue_url,  
$opt =  null)

Retrieves one or more messages from the specified queue, including the message body and message ID of each message.  Messages returned by this action stay in the queue until you delete them.  However, once a message is returned to a receive_message() request, it is not returned on subsequent receive_message() requests for the duration of the <VisibilityTimeout>.  If you do not specify a <VisibilityTimeout> in the request, the overall visibility timeout for the queue is used for the returned messages.  A default visibility timeout of 30 seconds is set when you create the queue.  You can also set the visibility timeout for the queue by using set_queue_attributes().  See Visibility Timeout for more information.

Access

public

Parameters

queue_urlstring (Required) The URL of the queue to perform the action on.
optarray (Required) Associative array of parameters which can have the following keys:

Keys for the $opt parameter

VisibilityTimeoutinteger (Optional) Must be an integer from 0 to 7200 (2 hours).
MaxNumberOfMessagesinteger (Optional) Maximum number of messages to return, from 1 to 10.  Not necessarily all the messages in the queue are returned.  If there are fewer messages in the queue than <MaxNumberOfMessages>, the maximum number of messages returned is the current number of messages in the queue.  Defaults to 1 message.
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/Query_QueryReceiveMessage.html
Example Usagehttp://tarzan-aws.com/docs/examples/sqs/receive_message.phps
Relatedsend_message(), delete_message()

delete_message()

public function delete_message($queue_url,  
$receipt_handle,  
$returnCurlHandle =  null)

Unconditionally removes the specified message from the specified queue.  Even if the message is locked by another reader due to the visibility timeout setting, it is still deleted from the queue.

Access

public

Parameters

queue_urlstring (Required) The URL of the queue to perform the action on.
receipt_handlestring (Required) The receipt handle of the message to delete, returned by receive_message().
returnCurlHandleboolean (Optional) A private toggle that will return the CURL handle for the request rather than actually completing the request.  This is useful for MultiCURL requests.

Returns

TarzanHTTPResponse object

See Also

AWS Methodhttp://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/Query_QueryDeleteMessage.html
Example Usagehttp://tarzan-aws.com/docs/examples/sqs/delete_message.phps
Relatedsend_message(), receive_message()

get_queue_size()

public function get_queue_size($queue_url)

Retrieves the approximate number of messages in the queue.

Access

public

Parameters

queue_urlstring (Required) The URL of the queue to perform the action on.

Returns

integer The Approximate number of messages in the queue.

See Also

Relatedget_queue_attributes()
Example Usagehttp://tarzan-aws.com/docs/examples/sqs/get_queue_size.phps