我正在编写一个查询不同数据库的价格的网络服务。 Web 服务写入一个新的 <Result>
节点进入 XML
调用 http://service.com/xml.php?search=carpet
时返回的页面一旦它从数据库中获得结果。不幸的是,发送到各种数据库的查询需要非常长的时间(总共最多 30 秒)。显然我不希望用户等待 30 秒,然后返回 XML 并用这些数据构建一个表;我希望它动态加载。
假设用户搜索“地毯”,数据库将返回多个产品,例如“红地毯” 和“黄地毯” em>。 "Red Carpet" 有两个动态加载到 "Red Carpet" 表中的 Distributor。 “黄地毯” 只有一个经销商。
我需要一个如下图所示的价格比较表,如果返回新文章,它会动态添加一个新表,如果为产品找到新的分销商,则会在表中添加一个新行。
您对如何实现这一点有什么建议吗?如何只接收从我的 xml.php 更改的数据?
价格比较表结构
XML 数据
<?xml version="1.0" encoding="UTF-8"?>
<Results>
<!--Given back within 5 seconds-->
<Result>
<ArticleNumber>Red Carpet</ArticleNumber>
<Manufacturer>Big Carpet Inc</Manufacturer>
<Distributor>Amazonas</Distributor>
<Prices>
<Pricebreak>
<Quantity>1</Quantity>
<Price>$ 1.20</Price>
</Pricebreak>
<Pricebreak>
<Quantity>10</Quantity>
<Price>$ 1.00</Price>
</Pricebreak>
<Pricebreak>
<Quantity>100</Quantity>
<Price>$ 0.50</Price>
</Pricebreak>
</Prices>
</Result>
<!--Given back within another 10 seconds-->
<Result>
<ArticleNumber>Red Carpet</ArticleNumber>
<Manufacturer>Big Carpet Inc</Manufacturer>
<Distributor>Veritas</Distributor>
<Prices>
<Pricebreak>
<Quantity>1</Quantity>
<Price>$ 0.90</Price>
</Pricebreak>
<Pricebreak>
<Quantity>5</Quantity>
<Price>$ 0.70</Price>
</Pricebreak>
</Prices>
</Result>
<!--Given back within another 5 seconds-->
<Result>
<ArticleNumber>Yellow Carpet</ArticleNumber>
<Manufacturer>Smallrug Corporation</Manufacturer>
<Distributor>Veritas</Distributor>
<Prices>
<Pricebreak>
<Quantity>1</Quantity>
<Price>$ 3.90</Price>
</Pricebreak>
<Pricebreak>
<Quantity>10</Quantity>
<Price>$ 2.70</Price>
</Pricebreak>
</Prices>
</Result>
</Results>
最佳答案
...actually the queries are not to an sql data source but to drivers that get information out of html websites...
如果是这种情况,那么我建议你在调用你的网页时不要这样做。而是让一些其他脚本作为 cron 任务或服务运行,根据数据的易变性定期轮询此数据。每 5 分钟一次,或每小时一次,每天一次?并将其填充到您的本地数据库中,您可以以更快的速度进行轮询。这将允许您在用户选择时加载您想要的任何数据,而无需等待解析器。
有效地向您的网络服务添加一个缓存层,以便您可以让您的应用程序快速运行,而不必依赖于按需解析数据。
此外,如果自动过程不可用,当您知道数据已更新时,您可以手动进行“更新”。
关于php - 使用 Javascript 和 PHP 动态添加查询 XML 源的新表和行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6004959/