# PHP 1 - Install php of version 5.5.0 or above . 2 - Install composer for your system . 3 - go to your directory and install aws-sdk for php using command ```php composer require aws/aws-sdk-php ``` 4 - You can use the below given Composer command to install the latest version of the AWS SDK for PHP as a dependency. ```php php -d memory_limit=-1 composer.phar require aws/aws-sdk-php ``` 4- Make a connection with the EQS client. To make the connection with the EQS client , you need to pass configurations and credentials. **Configurations-** ```php region_name- your_region endpoint_url - eqs_endpoint_url (provided by e2e networks eqs service) ``` **Credentials-** aws_access_key_id - your_access_key_id aws_secret_key_id - your_secret_key_id ## Make connection with EQS You can make the connection with the EQS client in three ways **a)** You can directly pass the credentials and configurations at the time of making a session with the EQS client. **warning** - Hardcoded credentials in application is not recommended *edit your .php file* ```php “your region”, 'version' => '2012-11-05, //version of sdk 'endpoint' => “end_point_url_to_connect_with_eqs” ]; $credentials = new Credentials('eqs_access_key_id', “eqs_secret_access_key”); $eqs_client = new SqsClient([ 'credentials' => $credentials, 'region' => $config['region'], 'version' => $config['version'], 'endpoint' => $config['endpoint'] ]); ?> ``` b) you can put credentials and configurations in the config and credentials file , and these files should be located at **~/.aws/config**, **~/.aws/credentials** location. *put into* **~/.aws/config** *file* ```php [default] region =REGION put into ~/.aws/credentials file ``` *put into* **~/.aws/credentials** *file* ```php [default] aws_access_key_id = ACCESS_KEY_ID aws_secret_access_key = SECRET_KEY ``` *edit your .php file* ```php '2012-11-05', 'region' => “your_region”, 'endpoint' => “eqs_end_point_url_provided_by_e2e” ]); ?> ``` c) you can make the connection with the EQS client by passing the credentials and configuration into the **environment** variables file. *Install the vlucas/phpdotenv package using Composer* ```php composer require vlucas/phpdotenv ``` *using terminal* **(Linux, OS X or Unix)** ```php $ export AWS_ACCESS_KEY_ID = your_access_key_id $ export AWS_SECRET_ACCESS_KEY = your_secret_key $ export AWS_DEFAULT_REGION = your_eqs_region ``` *using terminal* **(Windows)** ```php > set AWS_ACCESS_KEY_ID = your_access_key_id > set AWS_SECRET_ACCESS_KEY = your_secret_key > set AWS_DEFAULT_REGION = your_eqs_region ``` **or**, *edit your environment variable file* ```php AWS_ACCESS_KEY_ID = your_access_key_id AWS_SECRET_ACCESS_KEY = your_secret_access_key AWS_DEFAULT_REGION = your_eqs_region ``` *edit your .php file* ```php load(); $eqs_client = new SqsClient([ 'version' => '2012-11-05', 'region' => getenv(AWS_REGION'), 'credentials' => [ 'key' => getenv('AWS_ACCESS_KEY_ID'), 'secret' => getenv('AWS_SECRET_ACCESS_KEY'), ], ]); ?> ``` above eqs_client is an object which has all methods related to queue operations. **Methods available in eqs_client** ## Change VisibilityTimeout **Request Syntax** ```php $result = $eqs_client->changeMessageVisibility([ 'QueueUrl' => 'QUEUE_URL', 'ReceiptHandle' => 'RECEIPT_HANDLE', 'VisibilityTimeout' => 123, ]); ``` **Parameters** **QueueUrl** (string)- [Required] The URL of the E2E EQS queue whose message's visibility is changed. **ReceiptHandle** (string) - [Required] The receipt handle is associated with the message whose visibility timeout is changed. This parameter is returned by the *ReceiveMessage* action **VisibilityTimeout** (integer) - [Required] The new value for the message's visibility timeout (in seconds) **Response Syntax** ```php null ``` ## Change VisibilityTimeout in batch ```php $result = $eqs_client->changeMessageVisibilityBatch([ 'QueueUrl' => 'QUEUE_URL', 'Entries' => [ [ 'Id' => 'MESSAGE_ID_1', 'ReceiptHandle' => 'RECEIPT_HANDLE_1', 'VisibilityTimeout' => 123, ], [ 'Id' => 'MESSAGE_ID_2', 'ReceiptHandle' => 'RECEIPT_HANDLE_2', 'VisibilityTimeout' => 456, ], ], ]); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue whose message's visibility is changed. **Entries** (Array) - [Required] (Associative Array) *id [Required]-(string) An identifier for this particular receipt handle used to communicate the result* *ReceiptHandle [Required] -(string) A receipt handle* *VisibilityTimeout - (string) The new value (in seconds) for the message’s visibility timeout* **Response Syntax** ```php [ 'Failed' => [ [ 'Code' => '', 'Id' => '', 'Message' => '', 'SenderFault' => true || false, ], // ... ], 'Successful' => [ [ 'Id' => '', ], // ... ], ] ``` ## Create queue **Request Syntax** ```php $params = [ 'QueueName' => 'my-queue', 'Attributes' => [ 'DelaySeconds' => '0', 'MaximumMessageSize' => '262144', 'MessageRetentionPeriod' => '345600', 'ReceiveMessageWaitTimeSeconds' => '0', 'VisibilityTimeout' => '30', ], 'tags' => [ 'Department' => 'Finance', ], ]; // Create the queue $result = $eqs_client->createQueue($params); ``` **Parameters** **QueueName** (string)- [Required] 1 - A queue name can have up to 80 characters 2 - Valid values: alphanumeric characters, hyphens ( -), and underscores ( _). **Attributes** (associative array)- Attributes could be 1 - DelaySeconds - Time(second), to which extent delivery of messages is delayed in the queue Valid values - 0 to 900 (second) default - 0 (second) 2 - MaximumMessageSize - The size of the message after which the queue will reject the message Valid values - 1,024 bytes (1 KiB) to 262,144 bytes (256 KiB) default - 262,144 bytes(256 KiB) 3 - MessageRetentionPeriod - Time to which extent a queue will retain a message Valid values - 60 seconds (1 minute) to 1,209,600 seconds (14 days) default - 345,600 (4 days) 4 - ReceiveMessageWaitTimeSeconds - Time to which extent *ReceiveMessage* action waits before receiving a message Valid values - 0 to 20 (seconds) default - 0 (second) 5 - VisibilityTimeout - The amount of time that a message in a queue is invisible to other consumers after a consumer retrieves it. Valid values - 0 to 43,200 seconds (12 hours) default - 30 second **tags** (associative array) - 1 - Adding more than 50 tags to a queue isn't recommended. 2 - A new tag with a key identical to that of an existing tag overwrites the existing tag. **Response Syntax** ```php { 'QueueUrl': 'string' } ``` ## Delete message **Request Syntax** ```php $eqs_client->deleteMessage([ 'QueueUrl' => 'QUEUE_URL', 'ReceiptHandle' => 'RECEIPT_HANDLE', ]); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue from which messages are deleted. **ReceiptHandle** (string) - [Required] The receipt handle is associated with the message to delete. **Response Syntax** ```php null ``` ## Delete message in batch **Request Syntax** ```php $result = $eqs_client->deleteMessageBatch([ 'QueueUrl' => 'QUEUE_URL', 'Entries' => [ [ 'Id' => 'MESSAGE_ID_1', 'ReceiptHandle' => 'RECEIPT_HANDLE_1', ], [ 'Id' => 'MESSAGE_ID_2', 'ReceiptHandle' => 'RECEIPT_HANDLE_2', ] ] ]); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue from which messages are deleted. **Entries** (Array) - [Required] (associative array) *id [Required]-(string) An identifier for this particular receipt handle used to communicate the result* *ReceiptHandle [Required] -(string) A receipt handle* **Response Syntax** ```php [ 'Successful' => [ [ 'Id' => 'string', ], // Additional successful entries ], 'Failed' => [ [ 'Id' => 'string', 'SenderFault' => true || false, 'Code' => 'string', 'Message' => 'string', ], // Additional failed entries ], ] ``` ## Delete queue **Request Syntax** ```php $result = $eqs_client->deleteQueue(array( // QueueUrl is required 'QueueUrl' => 'string', )); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue to delete. **Response Syntax** ```php null ``` ## Get queue attributes **Request Syntax** ```php $params = [ 'QueueUrl' => 'QUEUE_URL', 'AttributeNames' => ['All'], // Or specify specific attributes as an array ]; // Call the operation $result = $sqsClient->getQueueAttributes($params); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue from which attributes are get. **AttributeNames** (Array) - [Optional] A list of attributes for which to retrieve information *All - it specifies, returns all values* you can also specify specific attributes in the list *As - ['VisibilityTimeout' , 'MaximumMessageSize' , 'MessageRetentionPeriod' , 'ApproximateNumberOfMessages' ,'ApproximateNumberOfMessagesNotVisible' , 'CreatedTimestamp' , 'LastModifiedTimestamp' , 'QueueArn' , 'ApproximateNumberOfMessagesDelayed' , 'DelaySeconds' , 'ReceiveMessageWaitTimeSeconds']* **Response Syntax** ```php [ 'Attributes' => ['', ...], ] ``` ## Get queue url **Request Syntax** ```php $result = $eqs_client->getQueueUrl([ 'QueueName' => '', // REQUIRED ]); ``` **Parameters** **QueueName** (string) -[Required] The name of the queue whose URL must be fetched. **Response Syntax** ```php [ 'QueueUrl' => '', ] ``` ## List queue tags **Request Syntax** ```php $result = $eqs_client->listQueueTags([ 'QueueUrl' => 'string', ]); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue of which all the tags must be listed. **Response Syntax** ```php [ 'Tags' => ['', ...], ] ``` ## List queues **Request Syntax** ```php $result = $eqs_client->listQueues([ 'MaxResults' => , 'NextToken' => '', 'QueueNamePrefix' => '', ]); ``` **Parameters** **QueueNamePrefix** (string) - [Optional] A string to use for filtering the list results. Only those queues whose name begins with the specified string are returned. **NextToken** (string) - Pagination token to request the next set of results. **MaxResults** (integer) - [Optional] The maximum number of results to include in the response. Valid values - 1 to 1000 **Response Syntax** ```php [ 'NextToken' => '', 'QueueUrls' => ['', ...], ] ``` ## Purge queue delete all the messages from queue. **Request Syntax** ```php $result = $eqs_client->purgeQueue([ 'QueueUrl' => '', // REQUIRED ]); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue of which all the messages must be deleted. **Response Syntax** ```php null ``` ## Receive message ```php $result = $eqs_client->receiveMessage([ 'AttributeNames' => ['', ...], 'MaxNumberOfMessages' => , 'MessageAttributeNames' => ['', ...], 'QueueUrl' => '', // REQUIRED 'ReceiveRequestAttemptId' => '', 'VisibilityTimeout' => , 'WaitTimeSeconds' => , ]); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue from which messages are received. **AttributeNames** (Array) - A list of attributes that need to be returned along with each message. *All - it specifies, returns all values* you can also specify specific attributes in the list *As - ['VisibilityTimeout' , 'MaximumMessageSize' , 'MessageRetentionPeriod' , 'ApproximateNumberOfMessages' ,'ApproximateNumberOfMessagesNotVisible' , 'CreatedTimestamp' , 'LastModifiedTimestamp' , 'QueueArn' , 'ApproximateNumberOfMessagesDelayed' , 'DelaySeconds' , 'ReceiveMessageWaitTimeSeconds']* **MessageAttributeNames** (Array) - The name of the message attribute. **MaxNumberOfMessages** (integer) - The maximum number of messages to return. Valid range - 1 to 10 default - 1 **VisibilityTimeout** (integer) - The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request. **WaitTimeSeconds** (integer) - The duration (in seconds) for which the call waits for a message to arrive in the queue before returning. **Response Syntax** ```php [ 'Messages' => [ [ 'Attributes' => ['', ...], 'Body' => '', 'MD5OfBody' => '', 'MD5OfMessageAttributes' => '', 'MessageAttributes' => [ '' => [ 'BinaryListValues' => [, ...], 'BinaryValue' => , 'DataType' => '', 'StringListValues' => ['', ...], 'StringValue' => '', ], // ... ], 'MessageId' => '', 'ReceiptHandle' => '', ], // ... ], ] ``` ## Send message **Request Syntax** ```php $result = $eqs_client->sendMessage([ 'DelaySeconds' => , 'MessageAttributes' => [ '' => [ 'DataType' => '', // REQUIRED 'StringListValues' => ['', ...], 'StringValue' => '', ], // ... ], 'MessageBody' => '', // REQUIRED 'MessageDeduplicationId' => '', 'MessageGroupId' => '', 'MessageSystemAttributes' => [ '' => [ 'DataType' => '', // REQUIRED 'StringListValues' => ['', ...], 'StringValue' => '', ], // ... ], 'QueueUrl' => '', // REQUIRED ]); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue to which messages are send. **MessageBody** (string) - [Required] The message to send. The minimum size is one character. The maximum size is 256 KB. **DelaySeconds** (integer) - The length of time, in seconds, for which to delay a specific message. **MessageAttributes** (associative array) - Each message attribute consists of a Name, Type, and Value . Name, type, value and the message body must not be empty or null . (string) - name of the message attributes (associative array) - Value of message attributes 1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding. 2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images. (string) - [Required] Type of message attributes EQS support the following data type Binary, Number, String **MessageSystemAttributes** (associative array) - Each message system attribute consists of a Name, Type, and Value. The name, type, value and message body must not be empty or null. (string) - the name of the message attributes (associative array) - Value of message attributes 1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding. 2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images. (string) - Type of message attributes EQS support the following data type Binary , Number , String **Response Syntax** ```php [ 'MD5OfMessageAttributes' => '', 'MD5OfMessageBody' => '', 'MD5OfMessageSystemAttributes' => '', 'MessageId' => '', 'SequenceNumber' => '', ] ``` ## Send message in batch **Request Syntax** ```php $result = $eqs_client->sendMessageBatch([ 'Entries' => [ // REQUIRED [ 'DelaySeconds' => , 'Id' => '', // REQUIRED 'MessageAttributes' => [ '' => [ 'DataType' => '', // REQUIRED 'StringListValues' => ['', ...], 'StringValue' => '', ], // ... ], 'MessageBody' => '', // REQUIRED 'MessageDeduplicationId' => '', 'MessageGroupId' => '', 'MessageSystemAttributes' => [ '' => [ 'DataType' => '', // REQUIRED 'StringListValues' => ['', ...], 'StringValue' => '', ], // ... ], ], // ... ], 'QueueUrl' => '', // REQUIRED ]); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue to which messages are sent. **Entries** (Array) - [Required] A list of SendMessageBatchRequestEntry items. (Associative array) - Contains the details of a single E2E EQS message along with an Id. **Id** (string) - [REQUIRED] An identifier for a message in this batch is used to communicate the result. **MessageBody** (string) - [Required] The message to send. The minimum size is one character. The maximum size is 256 KB. **DelaySeconds** (integer) - The length of time, in seconds, for which to delay a specific message. **MessageAttributes** (associative array) - Each message attribute consists of a Name, Type, and Value. The Name, type, value and message body must not be empty or null. (string) - The name of the message attributes (associative array) - Value of message attributes 1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding. 2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images. (string) -[Required] Type of message attributes EQS support the following data type Binary, Number, String **MessageSystemAttributes** (associative array) - Each message system attribute consists of a Name, Type, and Value. Name, type, value and the message body must not be empty or null. (string) - The name of the message attributes (associative array) - Value of message attributes 1 - StringValue (string) - Strings are Unicode with UTF-8 binary encoding. 2 - BinaryValue (bytes) - Binary type attributes can store any binary data, such as compressed data, encrypted data, or images. (string) - Type of message attributes EQS support following data type Binary , Number , String **Response Syntax** ```php [ 'Failed' => [ [ 'Code' => '', 'Id' => '', 'Message' => '', 'SenderFault' => true || false, ], // ... ], 'Successful' => [ [ 'Id' => '', 'MD5OfMessageAttributes' => '', 'MD5OfMessageBody' => '', 'MD5OfMessageSystemAttributes' => '', 'MessageId' => '', 'SequenceNumber' => '', ], // ... ], ] ``` ## Tag queue **Request Syntax** ```php $result = $eqs_client->tagQueue([ 'QueueUrl' => '', // REQUIRED 'Tags' => ['', ...], // REQUIRED ]); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue. **Tags** (associative array) - [Required] The list of tags to be added to the specified queue. **Response Syntax** ```php null ``` ## Untag queue **Request Syntax** ```php $result = $eqs_client->untagQueue([ 'QueueUrl' => '', // REQUIRED 'TagKeys' => ['', ...], // REQUIRED ]); ``` **Parameters** **QueueUrl** (string) - [Required] The URL of the E2E EQS queue. **TagKeys** (Array) - [Required] The list of tags to be removed from the specified queue. **Response Syntax** ```php null ``` ---