Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in cURL request: name lookup timed out

I wrote some code that fill a login form and submit it via post method. Like:

    $config = array(
        'adapter' => 'Zend_Http_Client_Adapter_Curl',
    );      

    $this->siteObj = new Zend_Http_Client('http://example.com', $config);
    $this->siteObj->setCookieJar();
    $this->siteObj->setUri('http://example.com/login');
    $this->siteObj->setParameterPost( 'data[User][name]', 'user' );
    $this->siteObj->setParameterPost( 'data[User][password]', 'password' );
    $response = $this->siteObj->request('POST');

its works fine, but some times this error occur:

Error in cURL request: name lookup timed out

Error: An Internal Error Has Occurred.

whats the problem? what can I do to solve it?

like image 580
Abdoljabbar Avatar asked Oct 31 '12 08:10

Abdoljabbar


2 Answers

I encountered the same problem:

  • From the shell, curl worked.
  • From the shell, the PHP script worked.
  • PHP could not ping the website.
  • The DNS config was right.

After restarting Apache, it worked. So strange.

like image 163
herderwu Avatar answered Nov 14 '22 12:11

herderwu


It can be a timeout problem. Try adjusting the connection timeout:

$config = array(
  'adapter' => 'Zend_Http_Client_Adapter_Curl',
  'timeout' => 100
);

you can also set single curl options:

$config = array(
    'adapter'   => 'Zend_Http_Client_Adapter_Curl',
    'curloptions' => array(
        CURLOPT_USERAGENT      => 'Zend_Curl_Adapter',
        CURLOPT_HEADER         => 0,
        CURLOPT_VERBOSE        => 0,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_TIMEOUT        => 10,
        CURLOPT_SSL_VERIFYPEER => false,
    ),
);

If you find out that it is a timeout issue, I would not suggest to increase too much the timeout parameter, but rather to make a for loop with a number of retries.

like image 5
luigif Avatar answered Nov 14 '22 11:11

luigif