2

I have an url with RSS feed:

$url = 'http://www.myurl.com/sth?format=RSS';

I can open it in a browser without a problem. But

$feed->load($url) 

returned 'false'. So I started investigating:

$ch = curl_init($file);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);           
print curl_error($ch); // prints 'couldn't connect to host'
echo "CODE: ".$retcode; // $retcode is 0

$file_headers = get_headers($file);
echo $file_headers[0]; // is null

So, what can be the reason for such behaviour? Is some port blocked on myurl.com server? Is there a way to work around it (like create local copy of the file and work on it)?

Adam
  • 125
  • 10
  • could be no outgoing http connections allowed, could be a security setting, could be the remote server blocking your request. simple test: log into a shell on the server and try to `telnet www.myurl.com 80` and see if that connects. – Marc B Dec 18 '14 at 16:13
  • See http://stackoverflow.com/questions/9922562/how-to-resolve-curl-error-7-couldnt-connect-to-host?answertab=votes#tab-top – toto21 Dec 18 '14 at 16:27
  • whats your hosting platform? – unixmiah Dec 18 '14 at 16:34

3 Answers3

0

Probably the site has some block for external connections implemented, such check for User-Agent, referal...

Alex M.
  • 635
  • 1
  • 6
  • 19
0

maybe the server is doing some sniffing and doesnt serve anything on that url if it finds that curl is doing the work. you could try phantomJS and/or Selenium to get around such filters. Selenium has PHP bindings.

timwaagh
  • 303
  • 3
  • 14
-1

If you're on CentOS (known issue on that flavour), do the following to test and make sure that's the not issue. later you can later issue specific filtering.

> emacs  /etc/selinux/config

locate following line
SELINUX=enforcing

Change this to
SELINUX=disabled

save the file and try again. it could be your localhost firewall if you can open it in a browser without a problem.

if this is an issue, set SELinux back to enforcing and issue

setsebool -P httpd_can_network_connect

if you want httpd to be able to connect to tcp ports

unixmiah
  • 3,081
  • 1
  • 12
  • 26
  • This seems like it'd have fairly significant security implications that should be mentioned beyond "just do this!". – ceejayoz Dec 18 '14 at 16:21
  • this seems like you haven't read my post? its to test and set it back to what it was, then use setsebool to allow httpd to figure out the problem. – unixmiah Dec 18 '14 at 16:33
  • It seems like you're not aware that SO has timestamps. You added that five minutes after my comment, so for obvious reasons, my comment did not deal with your *future* revisions. – ceejayoz Dec 18 '14 at 16:49
  • rgr that to timestamps – unixmiah Dec 18 '14 at 17:52