• The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Resolved file_get_contents() silent failure

stvnthomas

New Pleskian
I have two sites on the same server. Site 1 is set up to fetch content from Site 2 via an api endpoint but it gets a 500 Internal Server Error. I've tested with file_get_contents() and curl and the problem exists with both options. I've scoured the server and website logs and there is no record of the error. I've also tested it the other way around, Site 2 fetching a resource from Site 1 and same problem. So it's a server issue. allow_url_fopen is enabled.

However, both sites can file_get_contents() and curl to external resources. For example, they can both load content from an external test endpoint - JSONPlaceholder - Fake online REST API for developers. And I can successfully hit the Site 2 endpoint from my local dev machine or by directly loading the resource in the browser. I just can't get Site 1 to connect to Site 2 endpoint.

Anyone experience something similar?
 
When you get a 500 error, the web server error log has logged it and normally shows an easy-to-understand reason for it. Have you checked the error_log entry? What does it say?
 
Thank you for the response Peter!

I was able to figure it out over the weekend. The script would time out and show a 500 error, regardless of how simple the fetched data was ("Hello World!" text) or the timeout length. Turns out, file_get_contents() and curl aren't able to resolve any domains on the same server. I was able to query the endpoint with curl and setting CURLOPT_RESOLVE:

$ch = curl_init('http://www.example.com/feed');
curl_setopt($ch, CURLOPT_RESOLVE, array('www.example.com:80:192.168.100.240'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close($ch);

The strange thing is I checked the website and server logs and there's no reference to the 500 error. tail'd the logs while generating the 500 and nothing shows up at any point.

The above works but I'm not sure if this is the right fix or it the problem is indicative of something wrong/misconfigured on the server or from the server being behind a NAT. Any insight there would be appreciated. :)
 
You are apparently behind a NAT and have no internal DNS, and your scripts try to connect to the external IP they get from the external DNS. Try to add your hostnames and local IP(s) to /etc/hosts.
As for the 500: Your request did not reach the called site at all, so it can only be in the log of the calling server, if at all. Might just as well be a fake response generated by curl itself.
 
Back
Top