'us-west-2', 'version' => 'latest' ]); $dynamodb = $sdk->createDynamoDb(); $tableName = 'ProductCatalog'; $totalSegments = 5; $params = array( 'TableName' => $tableName, 'ExpressionAttributeValues' => array ( ':val1' => array('S' => 'Book') ) , 'FilterExpression' => 'contains (Title, :val1)', 'Limit' => 10, 'TotalSegments' => $totalSegments ); // Build an array of Scan commands - one for each segment $commands = []; for ($segment = 0; $segment < $totalSegments; $segment++) { $params['Segment'] = $segment; $commands[] = $dynamodb->getCommand('Scan',$params); } // Setup a command pool to run the Scan commands concurrently // The 'fulfilled' callback will process the results from each command // The 'rejected' callback will tell why the command failed $pool = new CommandPool($dynamodb,$commands,[ 'fulfilled' => function($result, $iterKey, $aggregatePromise) { echo "\nResults from segment $iterKey\n"; // Do something with the items foreach ($result['Items'] as $item) { echo "Scanned item with Title \"" . $item['Title']['S'] . "\"\n"; } }, 'rejected' => function ($reason, $iterKey, $aggregatePromise) { echo "Failed {$iterKey}: {$reason}\n"; } ]); $promise = $pool->promise(); $promise->wait(); // snippet-end:[dynamodb.php.codeexample.Scan_ParallelScan] ?>