XML ファイルに大量のデータがありますが、PHP コードを使用してデータを取得しているときに、Web ページが処理されてハングします。XML (都市名に関連するデータ) には 17,000 を超えるレコードがあります。州ごとにデータをフィルタリングする必要があるという提案をいくつか受け取りましたが、その提案を実装できません。
<?php
$q = $_GET["q"];
$xmlDoc = new DOMDocument();
$xmlDoc->load('http://aayam.co/wp-content/themes/squirreltheme/ifsc/cd_catalog.xml');
$x = $xmlDoc->getElementsByTagName('CITY');
for ($i = 0; $i <= $x->length - 1; $i++) {
// Process only element nodes
if ($x->item($i)->nodeType == 1) {
if ($x->item($i)->childNodes->item(0)->nodeValue == $q) {
$y = ($x->item($i)->parentNode);
}
}
}
$cd = ($y->childNodes);
for ($i = 0; $i < $cd->length; $i++) {
// Process only element nodes
if ($cd->item($i)->nodeType == 1) {
echo "<b style='color:green;'>" . $cd->item($i)->nodeName . ":</b> ";
echo "<div style='color:green;'>" . $cd->item($i)->childNodes->item(0)->nodeValue . " </div>";
echo "<br>";
}
}