benphp Posted July 13, 2016 Share Posted July 13, 2016 I can use both file_get_contents and CURL to fetch the contents of a file on my server, but when I attempt to read a file from outside the server, both just spin forever, never reading the file. I'm on IIS7 - and Curl is installed and running. I can browse to the locations with no trouble, but if I attempt to fetch the files using PHP, I get nothing. Is there some other setting in IIS that I need to enable or disable? What am I missing? Neither works: $sourceLink = "http://www.google.com"; $sourcePageHTML = file_get_contents($sourceLink); print $sourcePageHTML; $ch = curl_init("http://www.google.com"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $data = curl_exec($ch); print($data); Both work: $sourceLink = "http://myserver/myfile.php"; $sourcePageHTML = file_get_contents($sourceLink); print $sourcePageHTML; $ch = curl_init("http://myserver/myfile.php"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $data = curl_exec($ch); print($data); Quote Link to comment https://forums.phpfreaks.com/topic/301472-cant-fetch-external-file-what-am-i-doing-wrong/ Share on other sites More sharing options...
Jacques1 Posted July 13, 2016 Share Posted July 13, 2016 What happens when you use cURL or wget on the command line without PHP involved? Either way, you must have error handling when you call an external library. The fire-and-forget strategy doesn't work (as you can see). Check for errors, log the message, and I'm sure you'll get useful information. Quote Link to comment https://forums.phpfreaks.com/topic/301472-cant-fetch-external-file-what-am-i-doing-wrong/#findComment-1534468 Share on other sites More sharing options...
benphp Posted July 13, 2016 Author Share Posted July 13, 2016 (edited) CURL is a dll on my Windows server - I don't know how to run that from CMD - unless I download the standalone curl.exe. If I wait half an hour or so I finally get an error from fie_get_contents: Warning: file_get_contents(http://www.google.com) [ function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. My intuition is that there's some server or network setting that is denying the HTTP request from the server. Edited July 13, 2016 by benphp Quote Link to comment https://forums.phpfreaks.com/topic/301472-cant-fetch-external-file-what-am-i-doing-wrong/#findComment-1534471 Share on other sites More sharing options...
Jacques1 Posted July 14, 2016 Share Posted July 14, 2016 My intuition is that there's some server or network setting that is denying the HTTP request from the server. That's why I'm asking about the command line. I see no indication for a PHP problem, but this may very well be a network issue (e. g. a firewall which blocks outgoing HTTP requests). Without concrete information, there's nothing I could do from here. Check the firewall settings. Download a file from the command line (however this may work in Windows). When in doubt, use a packet sniffer to anaylze the exact network traffic. Quote Link to comment https://forums.phpfreaks.com/topic/301472-cant-fetch-external-file-what-am-i-doing-wrong/#findComment-1534472 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.