You are here:  » What to do when MagicParser.php will not open file


What to do when MagicParser.php will not open file

Submitted by keyesque2 on Fri, 2010-12-17 23:49 in

What to do when MagicParser.php will not open a file?

Tried basic analysis at http://www.magicparser.com/node/53

Which gives "could not open " // right after...if (!$fp)

The http request does open even when loaded in the browser.

Looking at that file, it looks like it could be quite involved.

Are there common areas that cause a block when cued by this latter error?

ADDED to POST: COULD IT BE THE SPACES?

url is like:
http://thefeed.com?partnerid=5w524s2da1kdw4&z=maintenance&s=CA&useragent=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13&ipaddress=45.139.14.751

(among the user agent)

Submitted by support on Sat, 2010-12-18 08:23

Hi,

As it is a URL that you are passing directly to MagicParser_parse() it is likely that URL wrappers are not enabled on your server. URL wrappers are what PHP uses to allow scripts to fopen() a URL - more info here:

http://uk2.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen

However, it is common that CURL is installed which is an alternative way to access a remote URL, so it would be worth trying the following code as an alternative, which may well work:

$ch = curl_init("<url>");
curl_setopt($ch, CURLOPT_HEADER, 0 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec ( $ch );
MagicParser_parse("string://".$xml,myRecordHandler,"xml|FORMAT/STRING/") ;

Replace with the URL that you are using, and xml|FORMAT/STRING/ with the value you are currently using and that should do the trick if you are not able to have URL wrappers enabled on your hosting account...

Hope this helps!

Cheers,
David.
--
MagicParser.com

Submitted by keyesque2 on Sat, 2010-12-18 16:05

Thanks for the response David.

I have had the...print MagicParser_getErrorMessage();
That gives "could not open" followed by the url string.

URL wrappers are enabled, as is curl:

CURL support enabled
CURL Information libcurl/7.20.0 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5

So CURL must be flipped off to take a feed the ordinary way?
This is on for security, not doubt.

....................................
Working with your CURL alternative, when trying to integrate anything from the feed to test, I keep getting (even when I beleive to have corrected the last line quotes):

"Notice: Use of undefined constant myRecordHandler - assumed 'myRecordHandler' "

require("xmlParser/MagicParser.php");
$ch = curl_init("http://thefeedaddress.com"); //does work in browser
curl_setopt($ch, CURLOPT_HEADER, 0 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec ( $ch );
function myRecordHandler($item)
{
   print "<p>".$item["DESCRIPTION"]."</p>";
     print "<p>".MagicParser_getErrorMessage()."</p>";
}
MagicParser_parse("string://".$xml,myRecordHandler,"xml|channel/item/") ;

Submitted by support on Sat, 2010-12-18 20:02

Hi,

If it's working in a browse but not via fopen() or CURL, one possibility is that the feed server requires a normal looking web browser user-agent string. To try this using CURL, have a go with the following code:

require("xmlParser/MagicParser.php");
$ch = curl_init("http://thefeedaddress.com"); //does work in browser
curl_setopt($ch, CURLOPT_HEADER, 0 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13&ipaddress=1.2.3.4");
$xml = curl_exec ( $ch );
function myRecordHandler($item)
{
  print "<p>".$item["DESCRIPTION"]."</p>";
}
if (!MagicParser_parse("string://".$xml,myRecordHandler,"xml|channel/item/"))
{
  print "<p>".MagicParser_getErrorMessage()."</p>";
}

Spaces in the URL shouldn't be a problem as they are normally handled correctly, but I noticed the URL in your post includes a useragent parameter so i've made it use the same value in the above code. Double check whether the ipaddress parameter has to match the address of your server...

If that doesn't help, if you could email me the URL I'll check it out on my test server for you...

Cheers,
David.

Submitted by keyesque2 on Sat, 2010-12-18 21:03

I emailed you, and it does not look like the ip has to match my local machine or server, at least with this in testing mode.

Submitted by keyesque2 on Sun, 2010-12-19 15:47

David,

Thank you for your help on this.

That url string. When urlencode is placed, wherever there is gap, allows the request.
Here it is useragent though have it on user ip too.

It now works even without CURL on my server. Though I appreciate the workaround.

Then there was the ommision of rss at the end, in "XML|RSS/.."