douyi5961 2017-03-21 16:58
浏览 1918
已采纳

Laravel - Guzzle:获取GuzzleHttp \ Exception \ ConnectException:cURL错误6无法随机解析主机

This is probably the weirdest situation that I ever seen. Basically I have a system built in Laravel 5.1 which needs to make a request to an external system. The thing is, sometimes it works but sometimes I get

GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: hosthere

Absolutely nothing changes, in terms of code. I run the application with exactly the same parameters and sometimes I get the error, sometimes I get the right response.

Any ideas?

Thanks in advance

EDIT 2 When I execute nslookup domainthatineedtouse.com I get

;; Got SERVFAIL reply from 8.8.8.8, trying next server
Server: 8.8.4.4
Address:    8.8.4.4#53

Non-authoritative answer:
Name:   domainthatineedtouse.com
Address: therealipaddressishere

Can this be related to the issue?

EDIT This is part of the class that is making the connection.

<?php


use GuzzleHttp\ClientInterface;

class MyClass
{
    const ENDPOINT = 'http://example.com/v1/endpoint';

    /**
     * @var \GuzzleHttp\ClientInterface
     */
    protected $client;

    /**
     * @var string The api key used to connect to the service
     */
    protected $apiKey;

    /**
     * Constructor.
     *
     * @param $apiKey
     * @param ClientInterface $client
     */
    public function __construct($apiKey, ClientInterface $client)
    {
        $this->client = $client;
        $this->apiKey = $apiKey;
    }

    /**
     * Here is where I make the request
     *
     * @param $param1
     * @param $param2
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function makeTheRequest($param1, $param2)
    {
        return $this->client->request('get', self::ENDPOINT, [
            'query' => [
                'api_token' => $this->apiKey,
                'parameter_1' => $param1,
                'parameter_2' => $param2,
            ]
        ]);
    }
}
  • 写回答

3条回答 默认 最新

  • dqbh8054 2017-03-22 15:02
    关注

    I hope this helps. Basically the problem was related to the server:

    https://twitter.com/digitalocean/status/844178536835551233

    In my case, I just needed to reboot and everything seems fine now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法