You are here:  » demo works - website doesn't


demo works - website doesn't

Submitted by miele on Fri, 2011-07-15 14:26 in

Hello,

The url i am trying to parse works in the demo. However, it does not on my own website. I am getting a gateway timeout after about a minute. If i am trying another url, the code works just fine.

I tried the url wrappers, but as other urls are working this cannot be the problem.

Any help?

This is the code i am trying at the moment:

<?php
  require("MagicParser.php");
  function myRecordHandler($record)
  {
    // This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    print_r($record);
  }
  MagicParser_parse("{link saved}","xml|FEED/ENTRY/");
?>

Thanks,

Miele

Submitted by support on Fri, 2011-07-15 14:41

Hello Miele,

This is almost certainly because URL Wrappers are not enabled on your PHP installation. Please see the following URL for more information:

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

However, it is becoming more common for CURL to be available as an option for retrieving URLs, so that could be used an alternative. Here's the demo generated code but using CURL instead. Note that this retrieves the XML into a variables, and then parses using the "string://" prefix:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    
// This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    
print_r($record);
  }
  
$url "{link saved}";
  
$ch curl_init($url);
  
curl_setopt($chCURLOPT_HEADER0);
  
curl_setopt($chCURLOPT_RETURNTRANSFER1);
  
$xml curl_exec($ch);
  
MagicParser_parse("string://".$xml,"myRecordHandler","xml|FEED/ENTRY/");
?>

Note that I've removed the URL so don't forget to replace {link saved} with the actual URL you are trying to parse...

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by miele on Fri, 2011-07-15 16:20

Hi David,

Thanks for the reply!

I checked the php config of my website through phpinfo(); and apparently allow_url_fopen is switched 'on'.
I also tested the option with CURL but this isn't working either.

Must be something else, as the BBC news headlines are showing perfectly if I use that url.

Thanks for any further help!

Miele

Submitted by support on Fri, 2011-07-15 16:35

Hello Miele,

It may be that your source doesn't like the PHP/[version] user-agent. Reverting to the original demo-generated code (version that is working fine with the BBC News RSS feed), try adding the following to the top of your script (second line, just after the opening PHP tag):

  ini_set("user_agent", "Mozilla/5.0");

Hope this helps,
Cheers,
David.

Submitted by miele on Fri, 2011-07-15 16:40

Hey David,

This isn't working either.

My test-code is now:

<?php
  ini_set("user_agent", "Mozilla/5.0");
  require("MagicParser.php");
  function myRecordHandler($record)
  {
    // This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    print_r($record);
    // The following code will print out each field in your sample data:
  }
  $url = "{link saved}";
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $xml = curl_exec($ch);
  curl_close($ch);
  MagicParser_parse("string://".$xml,"myRecordHandler","xml|FEED/ENTRY/");
?>

To see the behaviour of this all you can check: {link saved}

Thanks

Miele

Submitted by support on Fri, 2011-07-15 16:50

Hello Miele,

The ini_set method would only apply to the normal (fopen()) access method - have a go with:

<?php
  ini_set
("user_agent""Mozilla/5.0");
  require(
"MagicParser.php");
  function 
myRecordHandler($record)
  {
    
// This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    
print_r($record);
    
// The following code will print out each field in your sample data:
  
}
  
$url "{link saved}";
  
MagicParser_parse($url,"myRecordHandler","xml|FEED/ENTRY/");
?>

(i've left $url as a variable for convenience - don't forget to replace {link saved} with your source..)

Cheers,
David.

Submitted by miele on Sat, 2011-07-16 07:35

Hi David,

Thanks for the help. However, I still didn't get it to work.
I will try to contact my ISP to see if they can help.

Miele

Submitted by support on Sat, 2011-07-16 07:52

Hello Miele,

If you'd like to email me your latest script I'll check it out of my test server for you...

Cheers,
David.

Submitted by miele on Sat, 2011-07-16 10:01

Hi David,

I've sent you an email with the example.

BR,

Miele