简体   繁体   English

PHP Amazon SQS大数据

[英]PHP Amazon SQS Big Data

This is the first time for me using Amazon SQS. 这是我第一次使用Amazon SQS。

I am still a little confuse how to store big chunks of data more than 50000 results from the database and push to it to the queue. 我还是有点困惑如何存储来自数据库的超过50000个结果的大块数据并将其推送到队列。

AWS SQS instance 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 Query 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',
     ),
  ));
}

Or do I need to split the result into smaller result such as then count the number of pages 还是我需要将结果分成较小的结果,例如然后计算页数

$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
     ),
  ));
}

You are creating queues with the above, You have to push data to queue for the result. 您正在使用上述内容创建队列,您必须将数据推送到结果队列中。 there is function named sendmessage SQS SDK which helps you to push data to SQS Queue. 有一个名为sendmessage SQS SDK的函数,可帮助您将数据推送到SQS队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM