Lunarpages Web Hosting Forum

Author Topic: simplexml_load_file failure  (Read 296 times)

Offline ian.macky

  • Newbie
  • *
  • Posts: 4
simplexml_load_file failure
« on: May 21, 2019, 01:08:31 PM »
Hi...   I have some PHP which does bulk eBay searches for me-- I've been using it for years, but just ran it again for the first time in a few months and now simplexml_load_file() is failing on me every time, though I can't figure out why...     suggestions?

<html>
<head>
  <title>eBay US Search Results</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf8">
  <style type="text/css">
    body { font-family:sans; }
  </style>
</head>

<body bgcolor=white>
<h1>eBay US Search Results</h1>

<?php
$fh = fopen("search.dat", 'r') or die("can't open search data");
while ($theSearch = fgets($fh)) {
    $code = substr($theSearch, 0, 1);
    $query = substr($theSearch, 2);
    $safeQuery = urlencode($query);
    if ($code != "#") {
        echo "<h3>$query</h3>\n";
        if ($code == "y") {
            $url = "http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=xxx&SERVICE-VERSION=1.0.0&OPERATION-NAME=findItemsAdvanced&GLOBAL-ID=EBAY-US&keywords=$safeQuery&descriptionSearch=true&responseencoding=XML";
        }
        else if ($code == "n") {
            $url = "http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=xxx&SERVICE-VERSION=1.0.0&OPERATION-NAME=findItemsByKeywords&GLOBAL-ID=EBAY-US&keywords=$safeQuery&responseencoding=XML";
        }
        $result = simplexml_load_file($url);
        if ($result == FALSE)
            echo "<h2>FAILED</h2>\n";
        else
        {
            echo "<ul>\n";
            foreach ($result->searchResult->item as $item) {
                echo "<li><a href=$item->viewItemURL>$item->title</a>";
            }
            echo "</ul>\n";
        }
    }
}
fclose($fh);
?>

</body>
</html>

The "xxx" is my redaction for this posting; there's a proper value there in the real script.  If I try a search URL directly on my home machine it works fine and returns the expected results in XML etc-- it's just failing when I run it via my hosting on
mira.lunarpages.com (which is running PHP 7.2 (ea-php72)).

What's changed??

Thanks...

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6424
Re: simplexml_load_file failure
« Reply #1 on: May 21, 2019, 03:04:53 PM »
The last time you successfully ran this, what PHP version was your server? If it was "a few months ago", you might still have been at PHP 5.6. It depends on exactly when your server was "upgraded" to 7.2-only. Lots of code breaks at 7.2 :(. If you're sure you were running at 7.2 earlier, it must be something else.

Have you looked at the site error log in the control panel? Have you looked for error_log files scattered around your site? They may be able to tell you what went wrong, such as server restrictions on opening foreign URLs.

Finally, does eBay still allow http: (non-SSL) access? Have they made any API changes recently?
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline ian.macky

  • Newbie
  • *
  • Posts: 4
Re: simplexml_load_file failure
« Reply #2 on: May 21, 2019, 06:44:50 PM »
The last time you successfully ran this, what PHP version was your server? If it was "a few months ago", you might still have been at PHP 5.6. It depends on exactly when your server was "upgraded" to 7.2-only. Lots of code breaks at 7.2 :(. If you're sure you were running at 7.2 earlier, it must be something else.

Hi.  I may well have been on PHP 5.6 last time I ran this.  I wish I had a choice but  MultiPHP Manager says the version# is inherited and I can't change it.

Have you looked at the site error log in the control panel? Have you looked for error_log files scattered around your site? They may be able to tell you what went wrong, such as server restrictions on opening foreign URLs.

Yes, but there's nothing in the error log that is of any help (no indication of a problem at all).

Finally, does eBay still allow http: (non-SSL) access? Have they made any API changes recently?

I tried one of the search URLs directly from my box, as http:, and it works fine.

I'm not seeing anything in the documentation for simplexml_load_file that is of any help...

There's zero information as to what's wrong....  simplexml_load_file just returns FALSE.  Aarrgh!

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6424
Re: simplexml_load_file failure
« Reply #3 on: May 22, 2019, 04:47:30 AM »
It's possible that the upgrade to PHP 7.2 broke something in the eBay API, but then I would expect to see an error message logged somewhere.

If your MultiPHP Manager still permits the selection of PHP 5.6 or 7.1, you should be able to select such by clicking on the dropdown menu. Don't forget to "apply" the change. It's possible that your server now only permits 7.2 (LP has abruptly withdrawn 7.1, and announced months ago that 5.6 was going away), in which case there's still a problem. If you can still get to 5.6 or 7.1 for the time being, and it works, you can at least narrow it down to a 7.2 incompatibility.

Take another look at all your error_logs and the control panel Error Log. They should have nothing in them, in normal operation. Can you share a sample of what you're getting reported, if it is happening in the code using the eBay API? Maybe it is reporting a problem, but you're overlooking it.

Be sure to study https://www.php.net/manual/en/function.simplexml-load-file.php and see if the call to simplexml_load_file is being used incorrectly (and 7.2 is stricter about it). Especially check if you're really getting a FALSE return, or if it's really a '0' (use === to check for false, not == ).
« Last Edit: May 22, 2019, 04:50:52 AM by MrPhil »
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline ian.macky

  • Newbie
  • *
  • Posts: 4
Re: simplexml_load_file failure
« Reply #4 on: May 22, 2019, 06:19:22 AM »
Take another look at all your error_logs and the control panel Error Log.

Aha.... I was only looking at Error Log....  my error_log shows a problem:

[21-May-2019 19:41:56 UTC] PHP Warning:  simplexml_load_file(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/penin2/public_html/search-uk.php on line 27

I updated my code for === and it's definitely returning FALSE (as I'd expect from the above).


Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6424
Re: simplexml_load_file failure
« Reply #5 on: May 22, 2019, 11:57:15 AM »
I don't know if you'll be able to set allow_url_fopen=1 in your php.ini. Go ahead and try it -- at worst, you'll have to ask support if they allow it. You might first try changing http: to https:, as I'm sure eBay is fully SSL by now.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline ian.macky

  • Newbie
  • *
  • Posts: 4
Re: simplexml_load_file failure
« Reply #6 on: May 22, 2019, 04:41:21 PM »
I don't know if you'll be able to set allow_url_fopen=1 in your php.ini. Go ahead and try it -- at worst, you'll have to ask support if they allow it. You might first try changing http: to https:, as I'm sure eBay is fully SSL by now.

I had already tried https: with no success, so I made a php.ini with allow_url_fopen=1 and it's working again!  Thanks for your help.