14

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?

Abdoljabbar
  • 574
  • 1
  • 6
  • 20

3 Answers3

11

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.

J.D.
  • 1,786
  • 2
  • 22
  • 34
herderwu
  • 131
  • 1
  • 5
  • I also experienced this. Success was intermittent, then it stopped working entirely, until I restarted apache and all was well. I have to say it doesn't exactly fill me with confidence. – Jerry Mar 31 '16 at 22:44
  • Just wanted to point out restarting Vagrant may be needed, if someone else is also using Vagrant. – Firze Dec 28 '16 at 08:25
  • In my case I got that error always after first CURL request during midnight PHP CRON script, but each other request several milliseconds later worked fine. Restart of Apache fixed failing of first request definitely! Thank you. – mikep Apr 27 '18 at 06:42
5

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.

luigif
  • 544
  • 4
  • 8
  • thanks, this solved my problem "PHP Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Unable to Connect to ssl://www.google.com:443. Error #0 ..." – max4ever Jan 17 '13 at 17:01
4

It means that your DNS server failed to return a response in time. Check your DNS configuration (e.g. /etc/resolv.conf on Linux), and make sure they are alive and functional. Also try to ping the host in the URL from the same sever to get an idea whether the problem only in PHP or the any application running on the server (more likely).

sagi
  • 5,619
  • 1
  • 30
  • 31
  • I checked DNS configuration and also ping the host, but seems it doesn't have any problem. as same as I said before this code sometimes works fine and sometimes this error has occurred. – Abdoljabbar Oct 31 '12 at 08:23
  • I have the same problem. I can ping. It seems that the amount of time required to get the ping info is quite long though. – user4951 Jan 23 '13 at 02:20