60+% 的请求给出 curl 错误 URL 错误 7: 无法连接

Posted

技术标签:

【中文标题】60+% 的请求给出 curl 错误 URL 错误 7: 无法连接【英文标题】:60+% of the requests give curl error URL error 7: Failed to connect 【发布时间】:2016-07-01 06:43:17 【问题描述】:

该错误是间歇性的,有时有效,有时无效,这使得调试非常困难。

机器: Windows 10 框架: Laravel 5.1 环境: 宅基地 2.2.1 Vagrant 1.8.1(Ubuntu 14.04.2 LTS GNU/Linux 3.13.0-32-generic x86_64) PHP 5.6.10-1+deb.sury.org 作曲家.lock “guzzlehttp/guzzle”:6.1.1, "get-stream/stream-laravel": "dev-master", CurlFactory.php 第 186 行中的 ConnectException: cURL 错误 7:无法连接到 us-east-api.getstream.io 端口 443:连接超时(参见 http://curl.haxx.se/libcurl/c/libcurl-errors.html) 在 CurlFactory.php 第 186 行 在 CurlFactory::createRejection(object(EasyHandle), array('errno' => '7', 'error' => '无法连接到 us-east-api.getstream.io 端口 443: 连接超时', ' url' => 'https://us-east-api.getstream.io/api/v1.0/feed/notification/1/?limit=7&api_key=XXX', 'content_type' => null, 'http_code' = > '0', 'header_size' => '0', 'request_size' => '0', 'filetime' => '-1', 'ssl_verify_result' => '0', 'redirect_count' => '0' , 'total_time' => '4.077293', 'namelookup_time' => '0.127791', 'connect_time' => '0', 'pretransfer_time' => '0', 'size_upload' => '0', 'size_download' = > '0', 'speed_download' => '0', 'speed_upload' => '0', 'download_content_length' => '-1', 'upload_content_length' => '-1', 'starttransfer_time' => '0 ', 'redirect_time' => '0', 'redirect_url' => '', 'primary_ip' => '', 'certinfo' => array(), 'primary_port' => '0', 'local_ip' => '', 'local_port' => '0')) 在 CurlFactory.php 第 150 行 在 CurlFactory::finishError(object(CurlHandler), object(EasyHandle), object(CurlFactory)) 在 CurlFactory.php 第 103 行 在 CurlHandler.php 第 43 行的 CurlFactory::finish(object(CurlHandler), object(EasyHandle), object(CurlFactory)) 在 CurlHandler->__invoke(object(Request), array('synchronous' => true, 'base_uri' => object(Uri), 'timeout' => '6', 'handler' => object(HandlerStack), ' allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) 在 Proxy.php 第 28 行 在 Proxy::GuzzleHttp\Handler\closure(object(Request), array('synchronous' => true, 'base_uri' => object(Uri), 'timeout' => '6', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false , 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) 在 Proxy.php 第 51 行 在 Proxy::GuzzleHttp\Handler\closure(object(Request), array('synchronous' => true, 'base_uri' => object(Uri), 'timeout' => '6', 'handler' => object(HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false , 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) 在 PrepareBodyMiddleware.php 第 42 行 在 PrepareBodyMiddleware->__invoke(object(Request), array('synchronous' => true, 'base_uri' => object(Uri), 'timeout' => '6', 'handler' => object(HandlerStack), ' allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) 在 Middleware.php 第 30 行 在 Middleware::GuzzleHttp\closure(object(Request), array('synchronous' => true, 'base_uri' => object(Uri), 'timeout' => '6', 'handler' => object( HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, ' track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) 在 RedirectMiddleware.php 第 68 行 在 RedirectMiddleware->__invoke(object(Request), array('synchronous' => true, 'base_uri' => object(Uri), 'timeout' => '6', 'handler' => object(HandlerStack), ' allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) 在 Middleware.php 第 59 行 在 Middleware::GuzzleHttp\closure(object(Request), array('synchronous' => true, 'base_uri' => object(Uri), 'timeout' => '6', 'handler' => object( HandlerStack), 'allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, ' track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) 在 HandlerStack.php 第 67 行 在 HandlerStack->__invoke(object(Request), array('synchronous' => true, 'base_uri' => object(Uri), 'timeout' => '6', 'handler' => object(HandlerStack), ' allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false)) 在 Client.php 第 268 行 在客户端->传输(对象(请求),数组('同步'=> true,'base_uri'=>对象(Uri),'超时'=>'6','处理程序'=>对象(HandlerStack),' allow_redirects' => array('max' => '5', 'protocols' => array('http', 'https'), 'strict' => false, 'referer' => false, 'track_redirects' => false), 'http_errors' => true, 'decode_content' => true, 'verify' => true, 'cookies' => false, '_conditional' => array('User-Agent' => 'GuzzleHttp/6.1. 1 curl/7.35.0 PHP/5.6.10-1+deb.sury.org~trusty+1'))) 在 Client.php 第 98 行

【问题讨论】:

【参考方案1】:

作为 Stream 的联合创始人之一,我可以告诉你,我们这边的事情进展顺利 :) 你也可以从 Stream 的 status page 中验证同样的情况。

您遇到的超时错误可能取决于很多事情。这两个是导致类似问题的最常见原因:

您的本地开发人员和我们的 API 端点之间的连接延迟缓慢/不一致

DNS 问题(例如,对 DNS TTL 的错误处理、错误的 DNS 服务器……)

我的建议是通过以下方式确保两者都得到照顾:

为您的开发环境增加 API 超时,在 stream-laravel 配置文件中确保您有 'timeout' => 10

确保您使用 Google DNS 之类的东西(它们工作得很好)IP 是 8.8.8.88.8.4.4 由于 Homestead 使用 Ubuntu,您可以参考 this link

【讨论】:

谢谢托马索!我们假设这与本地环境/流浪者有关,因为它似乎没有出现在我们的登台服务器上,它的开启和关闭很奇怪。我们还在这个问题上标记了 homestead / laravel,看看它是否是这个环境中常见的 curl 问题,并会尝试你的建议。谢谢。

以上是关于60+% 的请求给出 curl 错误 URL 错误 7: 无法连接的主要内容,如果未能解决你的问题,请参考以下文章

cURL 发布请求脚本给出“未定义的函数 curl_init”

Spotify:发布到 api/token 给出了错误的请求,但在 curl 中工作

Heroku 部署时出错。错误:RPC 失败; HTTP 504 curl 22 请求的 URL 返回错误:504

cURL函数库错误码说明之PHP curl_errno函数

URL 错误 0:cURL 请求重试了 3 次,没有成功

GET 请求在浏览器中工作,但在 curl 中给出错误 SSL_ERROR_SYSCALL