我有一个网站会在用户附近展示商家。它使用Google API执行此操作。它首先使用雷达搜索抓取附近的商家,抓住place_id并将其保存到数据库中(我将在稍后需要),然后使用地点ID来获取有关该地点的详细信息。如果符合某些标准,则将结果显示在表格中。但是,加载需要很长时间,我正试图弄清楚原因。如果它只是太多的信息,而且它的方式很好,但是我觉得我在代码中做了一些事情来减慢它的速度。为什么我的桌子需要这么长的时间才能加载
<?php
$xml = simplexml_load_file("https://maps.googleapis.com/maps/api/place/radarsearch/xml?location=39.53,-89.33&radius=10000&type=establishment&key=MYKEY") or die("Error: Cannot create object");
foreach($xml->result as $get)
{
if($i==7) break;
$xml2 = simplexml_load_file("https://maps.googleapis.com/maps/api/place/details/xml?placeid=" . $get->place_id . "&key=MYKEY") or die("Error: Cannot create object");
$sql = "SELECT * FROM Places WHERE GoogleID = '".$get->place_id."'";
$records = $conn->query($sql);
$grab = $records->fetch_assoc();
if($records->num_rows > 0)
{
//yay
}
Else
{
$MakeNew = "INSERT INTO Places (GoogleID, ConfirmedHiring) VALUES ('".$get->place_id."', 'No')";
if(mysqli_query($conn, $MakeNew))
{
$records = $conn->query($sql);
$grab = $records->fetch_assoc();
}
}
foreach($xml2->result->address_component as $item){if($item->type == "locality"){$placecity = $item->long_name;}}
echo "<tr>";
echo "<td data-title='Business'>" . $xml2->result->name . "</td>";
echo "<td data-title='Location'>" . $placecity . "</td>";
echo "<td data-title='Confirmed Hiring'>" .$grab["ConfirmedHiring"]. "</td>";
echo "</tr>";
$i++;
}
?>
get_content函数的定义有多少行是它拉出? –
我使用I变量,当I = 7时,它停止。所以7. –
好耶你有一个'break' – Drew