Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Guzzle/Laravel卷曲错误6:无法解析主机:api.coingecko.com_Php_Laravel_Guzzle - Fatal编程技术网

Php Guzzle/Laravel卷曲错误6:无法解析主机:api.coingecko.com

Php Guzzle/Laravel卷曲错误6:无法解析主机:api.coingecko.com,php,laravel,guzzle,Php,Laravel,Guzzle,好的,所以我有点被这个问题困住了。我有一个foreach循环(通常是50个结果),通过LaravelHTTP使用Guzzle查询API,结果非常不一致 我监视数据库中的插入,当它们进入时,有时进程看起来很慢,而其他时候,在返回x个结果后,进程将失败 cURL错误6:无法解析主机:api.coincecko.com 下面是我用来获取结果的实际代码 foreach ($json_result as $account) { var_dump($account[

好的,所以我有点被这个问题困住了。我有一个foreach循环(通常是50个结果),通过LaravelHTTP使用Guzzle查询API,结果非常不一致

我监视数据库中的插入,当它们进入时,有时进程看起来很慢,而其他时候,在返回x个结果后,进程将失败

cURL错误6:无法解析主机:api.coincecko.com

下面是我用来获取结果的实际代码

foreach ($json_result as $account) {

                    var_dump($account['name']);

                    $name = $account['name'];
                    $coingecko_id = $account['id'];
                    $identifier = strtoupper($account['symbol']);

                    $response_2 = Http::get('https://api.coingecko.com/api/v3/coins/'.urlencode($coingecko_id).'?localization=false');

                    if($response_2->successful()){

                        $json_result_extra_details = $response_2->json();

                        if( isset($json_result_extra_details['description']['en']) ){
                            $description = $json_result_extra_details['description']['en'];
                        }

                        if( isset($json_result_extra_details['links']['twitter_screen_name']) ){
                            $twitter_screen_name = $json_result_extra_details['links']['twitter_screen_name'];
                        }
                        
                    }else {
                        // Throw an exception if a client or server error occurred...
                        $response_2->throw();
                    }

                    $crypto_account = CryptoAccount::updateOrCreate(
                        [
                            'identifier' => $identifier
                        ],
                        [
                            'name' => $name,
                            'identifier' => $identifier,
                            'type' => "cryptocurrency",
                            'coingecko_id' => $coingecko_id,
                            'description' => $description,
                        ]);

                    //sleep(1);
    
                }
现在我知道我在每分钟100次调用的API速率限制内,所以我认为这不是问题所在。我想知道这是否是一个我无法控制的服务器/api问题,或者它是否与我的代码以及Guzzle是如何实现的有关

当我执行单个查询时,我似乎没有问题,问题似乎是在foreach循环中

任何建议都很好。谢谢

编辑


好的,请更新问题,我现在想知道这是否与Guzzle/Laravel有关。我将API更改为现在指向Twitter API,在80个同步请求之后,我得到了相同的错误。

我认为最好直接在Guzzle中使用异步请求

$request = new \GuzzleHttp\Psr7\Request('GET', 'https://api.coingecko.com/api/v3/coins?localization=false');

for ($i=0; $i < 50 ; $i++) {
    $promise = $client->sendAsync($request)
        ->then(function ($response) {
            echo 'I completed! ' . $response->getBody();
        });
    $promise->wait();
}
$request=new\GuzzleHttp\Psr7\request('GET','https://api.coingecko.com/api/v3/coins?localization=false');
对于($i=0;$i<50;$i++){
$promise=$client->sendAsync($request)
->然后(函数($response){
回显“我已完成!”。$response->getBody();
});
$promise->wait();
}

有关异步请求的更多信息:

谢谢,我将试一试,看看它是如何进行的。这在我的场景中没有什么不同。你最终找到了解决方案吗?我突然得到了非常相似的行为(使用我调用的API成功请求了80次之后)。在昨天之前,这根本不是问题…@shaneparsons不,在两次单独的域调用(coincecko和twitter)中遇到问题后,我认为这更有可能是我的结局。因此,我决定使用调度程序,每2分钟运行一次,最多只能获取40条记录,而不是一次性获取所有帐户记录和循环。这似乎起到了作用,到目前为止还没有失败。另外,这是您的本地/代客泊车问题,还是临时/生产问题?在我的情况下,这只是一个问题,当地的代客泊车。。。我只是想把这些点连接起来。@shaneparsons对我来说,这是本地使用Artisan的。从未在我的服务器上尝试过,因此我无法告诉您它是否仅限于本地版本。