这是我第一次使用 Amazon SQS。
我仍然有点困惑如何从数据库中存储超过 50000 个结果的大块数据并将其推送到队列中。
AWS SQS 实例
require_once __DIR__.'lib/aws/aws-autoloader.php';
try {
$aws_sqs_client = \Aws\Sqs\SqsClient::factory(array(
'region' => 'eu-west-1',
'credentials' => array(
'key' => AWS_ACCESS,
'secret' => AWS_SECRET
)
));
} catch ( Exception $e ) {
}
MYSQL查询
$q = 'SELECT user_id, user_email FROM user' // This has more than 50000 rows
// Is this correct way? it will create 50000 queues?
foreach ( $q as $key => $row ) {
$result = $client->createQueue(array(
'QueueName' => 'string',
'Attributes' => array(
'Queue_key_'.$key => 'string',
),
));
}
或者我是否需要将结果拆分成更小的结果,例如然后计算页数
$q = 'SELECT user_id, user_email FROM user LIMIT 1000, 1' // Count total number of pages
$total_page = 500 // example;
for($i=1;$i<$total_page;$i++) { // then push it to the queue
$result = $client->createQueue(array(
'QueueName' => 'string',
'Attributes' => array(
'Queue_key_'.$i => 'LIMIT 1000, ',$i, // Mysql LIMIT
),
));
}
最佳答案
你正在用上面的方法创建队列,你必须将数据推送到队列中以获得结果。有一个名为 sendmessage SQS SDK 的函数可以帮助您将数据推送到 SQS 队列。
关于PHP 亚马逊 SQS 大数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34043395/