1

The php cURL extension on the Apache server I've inherited from my predecessor doesn't work.

I'm using the following code:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://www.linkedin.com/nhome/');
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_STDERR, $fp);

    $response = curl_exec($ch);
    $errmsg = curl_error($ch);
    $cInfo = curl_getinfo($ch);
    curl_close($ch);

Which returns the error:

* name lookup timed out
* Couldn't resolve host 'www.linkedin.com'
* Closing connection #0

However if I use an IP address instead of an URL it works:

* About to connect() to 54.171.54.110 port 80
*   Trying 54.171.54.110... * connected
* Connected to 54.171.54.110 (54.171.54.110) port 80

I'm assuming this is a DNS issue? How should I begin to troubleshoot the problem?

  • 1
    It's the DNS settings. Look at /etc/resolv.conf, get the nameservers you are using, and change them if they are wrong. – ThoriumBR Feb 24 '16 at 12:25
0

Thanks to ThoriumBR's comment for a push in the right direction.

The nameserver listed in /etc/resolv.conf wasn't working, so I replaced it with google's public nameservers:

nameserver 8.8.8.8
nameserver 8.8.4.4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.