PHP 亚马逊 SQS 大数据

标签 php mysql amazon-web-services amazon-sqs aws-sdk

这是我第一次使用 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/

相关文章:

javascript - 如何将生成的php页面中的数据显示到另一个页面?

mysql 昨天日期与特定时间戳

java - AWS Secrets Manager 使用 AWS-SDK Java 更新 key 请求

amazon-web-services - 如何输出 IAM 角色并在另一个堆栈中使用它?

email - PHP 进程终止时发送电子邮件的最佳方式

php - 如何在 CodeIgniter 中自定义路由?

java - mcrypt(在 PHP 中)在 Java 中使用的任何等效项?

mysql - 升级到 MySQL 8.0 后,具有多个连接的查询停止工作,错误代码 2013

php - Mysql 不返回特定数字的选择查询

linux - 通过 AWS 上的 EC2 启动 Ubuntu VM 并安装 icecast2