Hello,
I'm new here and I'm totally new to XML. I have some experience in PHP but some other programming language.
I have read a tutorial to parse XML in PHP and successfully displayed the contents in the webpage using PHP, but I'm not really happy with the speed of loading of the page.
If I could get help on loading the page faster, I would very much appreciate your help.
This is the page I'm working on:
The code can be found here:
Or, here is the code itself:
On the line 27: $document = file("I am suspecting this is taking a long time to load. As soon as it loads the file, the display of the contents is instant.
Am I doing it wrong? Or is there a better way to load XML into a variable?
Again, I really appreciate your time even to look at my post. I'm very grateful.
I'm planning on using this code in the left panel of the front page of my website:
Thank you very much. Have a great day.
Sincerely,
Danzian
I'm new here and I'm totally new to XML. I have some experience in PHP but some other programming language.
I have read a tutorial to parse XML in PHP and successfully displayed the contents in the webpage using PHP, but I'm not really happy with the speed of loading of the page.
If I could get help on loading the page faster, I would very much appreciate your help.
This is the page I'm working on:
The code can be found here:
Or, here is the code itself:
Code:
<?php
$flag = 0;
$ip = "69.180.180.46";
$port = "81";
$portts = "8767";
$timeout = "1";
$nukeurl = "[URL unfurl="true"]http://www.stpaulairlines.com/page.php?height=1750&url2=http://";[/URL]
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, "start_tag", "end_tag");
xml_set_character_data_handler($parser, "tag_contents");
if ($ip and $port and $timeout)
{
$connection = @fsockopen("$ip", $port, $errno, $errstr, $timeout);
}
echo "<div align='center'>";
echo "<br>";
if(!$connection)
{
echo "<font color='#990000' > <b>Flight Server Offline</b></font>";
echo "<br>";
}
else
{
$document = file("[URL unfurl="true"]http://69.180.180.46:81/xml");[/URL]
echo "<font color='#006600' align='center' ><b>Flight Server Online</b></font>";
echo "<br><br>";
echo "Onine Pilots: ";
foreach ($document as $line)
{
xml_parse($parser, $line);
}
echo "<br>";
echo "<a href=$nukeurl" .$ip. ":" .$port. "/>Click here for <br>Details</a>";
xml_parser_free($parser);
echo "<br>";
echo "<br>";
echo "</div>";
}
function start_tag($parser, $name, $attribs)
{
global $flag;
if ($name=="CurrentPilots") $flag=1;
if ($name=="Name") $flag=2;
}
function end_tag($parser, $name)
{
global $flag;
if ($name=="CurrentPilots") $flag=0;
if ($name=="Name") $flag=0;
}
function tag_contents($parser, $data)
{
global $flag;
if ($flag==1)
echo "<font color='#0033CC' align='center' ><b>" .$data. "</b><br /></font>---------------------------<br>";
if ($flag==2)
echo "<font color='#FF6633' align ='center'><b>" .$data. "</b><br /></font>---------------------------<br>";
}
?>
On the line 27: $document = file("I am suspecting this is taking a long time to load. As soon as it loads the file, the display of the contents is instant.
Am I doing it wrong? Or is there a better way to load XML into a variable?
Again, I really appreciate your time even to look at my post. I'm very grateful.
I'm planning on using this code in the left panel of the front page of my website:
Thank you very much. Have a great day.
Sincerely,
Danzian