我正在从Unleashed API(仓库管理软件)中提取xml信息,目前遇到问题。我需要提取所有库存记录并计算它们。问题是我们大约有2800个,而Unleashed API只允许我一次提取1000条记录。为了解决这个问题,我必须分开拉三页,这花费了不合理的时间(大约两分钟)。
我有什么方法可以使这项工作更好?这是我提取XML信息的部分:
function getSku1($format) {
global $apiId, $apiKey;
if ($format == "xml")
return getXml($apiId, $apiKey, "StockOnHand/Page/1", "pageSize=1000");
else
return getJson($apiId, $apiKey, "StockOnHand/Page/1", "pageSize=1000");
}
function getSku2($format) {
global $apiId, $apiKey;
if ($format == "xml")
return getXml($apiId, $apiKey, "StockOnHand/Page/2", "pageSize=1000");
else
return getJson($apiId, $apiKey, "StockOnHand/Page/2", "pageSize=1000");
}
function getSku3($format) {
global $apiId, $apiKey;
if ($format == "xml")
return getXml($apiId, $apiKey, "StockOnHand/Page/3", "pageSize=1000");
else
return getJson($apiId, $apiKey, "StockOnHand/Page/3", "pageSize=1000");
}
这是准备将信息打印在表格中的部分。我排除了打印代码,因为它不是问题的一部分。该代码可以工作,但是需要很长时间。出于安全原因,我还更改了一些变量。
function testGetSku() {
global $valueproduct;
$xml1 = getSku1("xml");
$xml2 = getSku2("xml");
$xml3 = getSku3("xml");
htmlentities($xml1->asXML());
htmlentities($xml2->asXML());
htmlentities($xml3->asXML());
$availablproduct = 0;
$allocateproduct = 0;
$onpurchaseproduct = 0;
$totalproduct = 0;
$pointer = 0;
foreach ($xml1->StockOnHand as $stockonhand) {
$productgroup = $stockonhand->ProductGroupName;
if ($productgroup == "Group_name")
{
$availableproduct+= $stockonhand->QtyOnHand;
$allocatedproduct+= $stockonhand->AllocatedQty;
$onpurchaseproduct+= $stockonhand->OnPurchase;
$totalproduct+= $stockonhand->QtyOnHand;
$totalproduct+= $stockonhand->AllocatedQty;
$totalproduct+= $stockonhand->OnPurchase;
$valueproduct+= $stockonhand->TotalCost;
}
else
$pointer+= 1;
}
foreach ($xml2->StockOnHand as $stockonhand) {
$productgroup = $stockonhand->ProductGroupName;
if ($productgroup == "Group_name")
{
$availableproduct+= $stockonhand->QtyOnHand;
$allocatedproduct+= $stockonhand->AllocatedQty;
$onpurchaseproduct+= $stockonhand->OnPurchase;
$totalproduct+= $stockonhand->QtyOnHand;
$totalproduct+= $stockonhand->AllocatedQty;
$totalproduct+= $stockonhand->OnPurchase;
$valueproduct+= $stockonhand->TotalCost;
}
else
$pointer+= 1;
}
foreach ($xml3->StockOnHand as $stockonhand) {
$productgroup = $stockonhand->ProductGroupName;
if ($productgroup == "Group_name")
{
$availableproduct+= $stockonhand->QtyOnHand;
$allocatedproduct+= $stockonhand->AllocatedQty;
$onpurchaseproduct+= $stockonhand->OnPurchase;
$totalproduct+= $stockonhand->QtyOnHand;
$totalproduct+= $stockonhand->AllocatedQty;
$totalproduct+= $stockonhand->OnPurchase;
$valueproduct+= $stockonhand->TotalCost;
}
else
$pointer+= 1;
}
$ pointer仅用于验证数据是否确实在被提取。如果有人可以帮助我改善这一点,我将非常感激。