3

Does anyone know what happen on the error as below when calling curl even call yahoo page:

Error code 6 :Couldn't resolve host 'http://www.yahoo.com'; No data of requested type

PHP

 $sendurl = "http://www.yahoo.com";
 $ch = curl_init($sendurl);                                                                     
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);                                                                     
 $result = curl_exec($ch);

 if(!$result){
     echo $curl_errno($ch).":".curl_error($ch);
 }
AymDev
  • 6,626
  • 4
  • 29
  • 52
user831098
  • 1,803
  • 6
  • 27
  • 47

2 Answers2

3

This error mean that curl can't resolve host name.

There is problem with DNS server on computer where you run this script.

If you run script on your local computer then check it just open www.yahoo.com in your browser.

If you run script on remote server, then you should login to server by SHH and check ping www.yahoo.com. Or ask your hosting support team about this issue.

newman
  • 2,689
  • 15
  • 23
  • 1
    Yes, I using browser is running ok even ping also work fine. Just when call curl in php it will display the same issue. Will it be the setting on some XAMPP or apache? – user831098 Nov 28 '14 at 10:04
  • @user831098 then there is issue in communicate with cURL and DNS. Maybe this any firewall policies and it not allow curl connect ot DNS. Also you can try: http://stackoverflow.com/questions/1341644/curl-and-https-cannot-resolve-host or http://stackoverflow.com/questions/24967855/curl-6-could-not-resolve-host-google-com-name-or-service-not-known – newman Nov 28 '14 at 10:14
1

I think you're missing options for allowing redirects and https. Check it in your browser -> you will get redirected to https URL.

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
gskema
  • 3,141
  • 2
  • 20
  • 39