php - 在本地数据库中存储Amazon API数据

原文 标签 php mysql api amazon-web-services walmart-api

Storing Amazon API data in Local Database

I'm working on a site that pulls product price data from Amazon.com and Walmart. I'm guessing that in the future, it will also pull data from other places.

My first idea was to pull the data directly from Amazon (using their product advertising API) and then display the data on the site for every single visitor who landed on the page. That's not a bad idea if there aren't many product prices I'll be retrieving (or if the number of site visitors is low). I think that I will run into problems once the site gets busy and if i increase the number of product whose price i want to pull.

Using the Amazon and Walmart API, i was able to make successful REST api calls and parse the XML returned to obtain the information that i needed.

Does it make sense to store that information in a local database, update it say, every 1-5 minutes, and then get the site visitors to pull the pricing information from my local database instead of making an API call to Amazon and Walmart?

If I do go this route and create a function that uses the Amazon and Walmart API to pull price data, how do I then automatically run this function every 1 to 5 minutes in the background, 24/7/365?

Answer

Does it make sense to store that information in a local database

Yes. Actually this sounds exactly like a typical caching setup. I would recommend looking into Redis instead of using a relational database for this.

how do I then automatically run this function every 1 to 5 minutes in the background

Probably a Cron job. You would have to provide more information like where your application is running (AWS EC2 or somewhere else?) and if it is running on Linux or Windows, before I could give a more detailed recommendation.

翻译

我正在一个网站上,从Amazon.com和Walmart提取产品价格数据。我猜测将来还会从其他地方提取数据。

我的第一个想法是直接从亚马逊获取数据(使用其产品广告API),然后为登陆该页面的每个访问者在网站上显示数据。如果我要检索的产品价格不高(或者网站访问者人数很少),这不是一个坏主意。我认为一旦网站繁忙并且如果我增加要拉价的产品数量,我就会遇到问题。

使用Amazon和Walmart API,我能够成功进行REST api调用,并解析返回的XML以获取所需的信息。

将这些信息存储在本地数据库中,每1-5分钟更新一次,然后让网站访问者从我的本地数据库中获取定价信息,而不是对Amazon和Walmart进行API调用,是否有意义?

如果我按此路线创建了一个使用Amazon和Walmart API提取价格数据的函数,那么我如何在后台24/7/365每1至5分钟自动运行一次此函数?
最佳答案
将这些信息存储在本地数据库中是否有意义


是。实际上,这听起来像是典型的缓存设置。我建议调查Redis,而不是为此使用关系数据库。


  然后我如何每1到5分钟自动运行一次此功能
  背景


可能是Cron工作。您必须提供更多信息,例如您的应用程序在何处运行(AWS EC2或其他地方?),以及它是否在Linux或Windows上运行,然后才能给出更详细的建议。
相关推荐

php - PHP表格检查数组mysql中的复选框值时查询?

php - 无法从数组获取正确的值

php - cakePHP在模型中使用请求/身份验证数据的3个最佳实践(基于帐户的云服务)

php - 什么数据类型可用于在mysql中放置标志(布尔值)?

javascript - 尝试将数据从.php文件传递到.js文件

php - 更改子菜单时如何更改网页背景?

php - Symfony2:如何避免数据库中已经存在重复的实体?

php - Eclipse中的PHP 7调试器设置

javascript - 访问URL参数-PHP和Angular.js

php - 使用更新的MySQL库修复PHP数据库连接失败