SDK for PHP 3.x

WriteRequestBatch
in package

The WriteRequestBatch is an object that is capable of efficiently sending DynamoDB BatchWriteItem requests from queued up put and delete item requests.

requests. The batch attempts to send the requests with the fewest requests to DynamoDB as possible and also re-queues any unprocessed items to ensure that all items are sent.

Table of Contents

Methods

__construct()  : mixed
Creates a WriteRequestBatch object that is capable of efficiently sending DynamoDB BatchWriteItem requests from queued up Put and Delete requests.
delete()  : $this
Adds a delete item request to the batch.
flush()  : $this
Flushes the batch by combining all the queued put and delete requests into BatchWriteItem commands and executing them. Unprocessed items are automatically re-queued.
put()  : $this
Adds a put item request to the batch.

Methods

__construct()

Creates a WriteRequestBatch object that is capable of efficiently sending DynamoDB BatchWriteItem requests from queued up Put and Delete requests.

public __construct(DynamoDbClient $client[, array<string|int, mixed> $config = [] ]) : mixed
Parameters
$client : DynamoDbClient

DynamoDB client used to send batches.

$config : array<string|int, mixed> = []

Batch configuration options.

  • table: (string) DynamoDB table used by the batch, this can be overridden for each individual put() or delete() call.
  • batch_size: (int) The size of each batch (default: 25). The batch size must be between 2 and 25. If you are sending batches of large items, you may consider lowering the batch size, otherwise, you should use 25.
  • pool_size: (int) This number dictates how many BatchWriteItem requests you would like to do in parallel. For example, if the "batch_size" is 25, and "pool_size" is 3, then you would send 3 BatchWriteItem requests at a time, each with 25 items. Please keep your throughput in mind when choosing the "pool_size" option.
  • autoflush: (bool) This option allows the batch to automatically flush once there are enough items (i.e., "batch_size" * "pool_size") in the queue. This defaults to true, so you must set this to false to stop autoflush.
  • before: (callable) Executed before every BatchWriteItem operation. It should accept an \Aws\CommandInterface object as its argument.
  • error: Executed if an error was encountered executing a, BatchWriteItem operation, otherwise errors are ignored. It should accept an \Aws\Exception\AwsException as its argument.
Tags
throws
InvalidArgumentException

if the batch size is not between 2 and 25.

delete()

Adds a delete item request to the batch.

public delete(array<string|int, mixed> $key[, string|null $table = null ]) : $this
Parameters
$key : array<string|int, mixed>

Key of an item to delete. Format: [ 'key1' => ['type' => 'value'], ... ]

$table : string|null = null

The name of the table. This must be specified unless the "table" option was provided in the config of the WriteRequestBatch.

Return values
$this

flush()

Flushes the batch by combining all the queued put and delete requests into BatchWriteItem commands and executing them. Unprocessed items are automatically re-queued.

public flush([bool $untilEmpty = true ]) : $this
Parameters
$untilEmpty : bool = true

If true, flushing will continue until the queue is completely empty. This will make sure that unprocessed items are all eventually sent.

Return values
$this

put()

Adds a put item request to the batch.

public put(array<string|int, mixed> $item[, string|null $table = null ]) : $this
Parameters
$item : array<string|int, mixed>

Data for an item to put. Format: [ 'attribute1' => ['type' => 'value'], 'attribute2' => ['type' => 'value'], ... ]

$table : string|null = null

The name of the table. This must be specified unless the "table" option was provided in the config of the WriteRequestBatch.

Return values
$this
On this page