Forum Moderators: coopster

Message Too Old, No Replies

XML Retrieval in PHP

         

Lpe04

7:27 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



I am trying to learn PHP and have been working the last couple days on trying to get a program that I installed to retrieve product prices from an xml feed from another site. I am able to retrieve the price and display the information if I have the XML document local on my server, but if I attempt to retrieve an external URL it will not work (it usually times out trying to load the page).

Does anybody know a function for PHP 4.3.4 that will retrieve an XML document from an external server?

$myXML = file_get_contents($price_url);

does not work and neither does

$myXMLDoc = new XMLDocument("XML URL");
$myXML = $myXMLDoc->getXML();

altough this one will work locally. Any help would be greatly appreciated. Thanks.

coopster

4:22 am on Aug 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What, if any, error messages are you getting?

Lpe04

6:26 am on Aug 14, 2004 (gmt 0)

10+ Year Member



Well I have tried some new code:

<?php
// include a class-loading function
require_once("activelink/classes/include.php");
// import XML and XMLDocument classes
import("org.active-link.xml.XML");
import("org.active-link.xml.XMLDocument");
$filename = "http.....(link to xml URL)";
$handle = fopen($filename, "r");
$myXMLstring = fread($handle, filesize($filename));
fclose($handle);
$myXMLDoc = new XMLDocument();
$myXMLDoc -> parseFromString($myXMLString);
$myXML = $myXMLDoc->getXML();

$priceBranchArray = $myXML->getBranches("o1:OSTKXML/o1:OSTKPRODUCT",
"o1:Price");

print("Test1");
print($priceBranchArray[0]->getTagContent());
print("Test2<br>");
?>


Error Messages=

Warning: fopen(http://...Whichever XML URL I am linking to): failed to open stream: HTTP request failed!  ¦ؿ̺ @ӿ ~  on line 11

Warning: filesize(): Stat failed for [...(Whichever...] XML URL I am linking to) (errno=2 - No such file or directory) on line 12

Warning: fread(): supplied argument is not a valid stream resource on line 12

Warning: fclose(): supplied argument is not a valid stream resource on line 13

Fatal error: Call to a member function on a non-object on line 22

Lpe04

7:10 am on Aug 15, 2004 (gmt 0)

10+ Year Member



OK, I installed Apache and PHP 4.3.4 on my computer tonight and the scripts and code ran just fine. So apparently, something is wrong with my host server (I am guessing one of the PHP settings). They are trouble shooting it, but does anyone know what might be causing the server to not be able to retrieve external files?

coopster

10:39 pm on Aug 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Could be a number of things, including the version of PHP, safe mode configuration settings, disable_functions configuration setting...the list goes on. I would start with a simple fopen() and troubleshoot it. Check the server logs, php.ini configuration, etc.