NameSilo

cURL is unable to resolve a URL

Spaceship Spaceship
Watch

Barrucadu

Established Member
Impact
64
[resolved] cURL is unable to resolve a URL

As this is on my server, on my laptop, I'd guess it's something I've failed to set up correctly. Here's the function I wrote:
PHP:
  function get_file($url)
  {
	if(function_exists('curl_init'))
	  {
		$options = array(CURLOPT_RETURNTRANSFER => true,
						 CURLOPT_HEADER         => false,
						 CURLOPT_FOLLOWLOCATION => true,
						 CURLOPT_ENCODING       => "",
						 CURLOPT_USERAGENT      => "xml-spider",
						 CURLOPT_AUTOREFERER    => true,
						 CURLOPT_CONNECTTIMEOUT => 120,
						 CURLOPT_TIMEOUT        => 120,
						 CURLOPT_MAXREDIRS      => 10);

		$ch = curl_init($url);
		curl_setopt_array($ch, $options);
		$content = curl_exec($ch);
		$err = curl_errno($ch);
		$errmsg = curl_error($ch);
		$header = curl_getinfo($ch);
		curl_close($ch);

		$header['errno']   = $err;
		$header['errmsg']  = $errmsg;
		print_r($header); // Just for debugging

		return $content;
	  }
	else
	  {
		return file_get_contents($url);
	  }
  }
And the $header array is:
Code:
Array
(
    [url] => http://www.barrucadu.co.uk/foaf.rdf
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0
    [namelookup_time] => 0
    [connect_time] => 0
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => 0
    [upload_content_length] => 0
    [starttransfer_time] => 0
    [redirect_time] => 0
    [errno] => 6
    [errmsg] => Couldn't resolve host 'www.barrucadu.co.uk' // or whatever host I enter
)

However, file_get_contents also fails to get the file, so it's not just a cURL problem.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Your firewall ?
 
0
•••
I don't have a firewall, plus all other programs are able to resolve hostnames fine. There doesn't seem to be anything relevant in php.ini either.
I've asked on the forum for the Linux distro I use, so hopefully I'll get an answer soon.
 
0
•••
Hmm nothing looks wrong with the code. The only thing that I can think of that would stop file_get_contents working is if fopen wrappers are disabled. I would just advise to double check all settings on your local server and giving it a reboot.

Edit: Yeah check fopen_wrappers is enabled. I just disabled it on my local server and now I can't fetch any web page either. So that could be your problem.
 
0
•••
turn error reporting onto full (error_reporting(E_ALL)). This would show you if file_get_contents is set to allow external streams.

Also have you tried visiting the site in a browser on the laptop? If you can't flush your DNS.
 
0
•••
Code:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /srv/http/xmlparser.php on line 59

Warning: file_get_contents([url]http://www.barrucadu.co.uk/foaf.rdf[/url]) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /srv/http/xmlparser.php on line 59
XML Error: Invalid document end at line 1

That would explain it...
But how do I enable URL file-access?
 
0
•••
in php.ini enable the following option:-

allow_url_fopen
 
0
•••
Thanks, works perfectly now.
 
0
•••
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back