简体   繁体   English

cURL 错误 28:操作在 2000 毫秒后超时,收到 23000995 个字节中的 7276200 个

[英]cURL error 28: Operation timed out after 2000 milliseconds with 7276200 out of 23000995 bytes received

Description描述

I'm using Guzzle in my Laravel project.我在我的 Laravel 项目中使用 Guzzle。 I had a memory crash when I make a request to an API that return a huge payload.当我向返回巨大负载的 API 发出请求时,我发生了 memory 崩溃。

I have this on the top of my CURL.php class. I have get() that I use Guzzle.我把这个放在我的CURL.php class 的顶部。我有 get(),我使用 Guzzle。

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
use GuzzleHttp\FORCE_IP_RESOLVE;
use GuzzleHttp\DECODE_CONTENT;
use GuzzleHttp\CONNECT_TIMEOUT;
use GuzzleHttp\READ_TIMEOUT;
use GuzzleHttp\TIMEOUT;

class CURL {

    public static function get($url) {

        $client = new Client();
        $options = [
            'http_errors' => true,
            'force_ip_resolve' => 'v4',
            'connect_timeout' => 2,
            'read_timeout' => 2,
            'timeout' => 2,
        ];
        $result = $client->request('GET',$url,$options);
        $result = (string) $result->getBody();
        $result = json_decode($result, true);
        return $result;

    }

    ...

}

When I call it like this in my application, it request a large payload (30000)当我在我的应用程序中这样调用它时,它会请求一个大的有效负载 (30000)

$url = 'http://site/api/account/30000';
$response =  CURL::get($url)['data'];

I kept getting this error我一直收到这个错误

cURL error 28: Operation timed out after 2000 milliseconds with 7276200 out of 23000995 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html ) cURL 错误 28:操作在 2000 毫秒后超时,收到 23000995 个字节中的 7276200 个(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html

How do I avoid this?我该如何避免这种情况?

Should I increase these settings?我应该增加这些设置吗?

'connect_timeout' => 2,
'read_timeout' => 2,
'timeout' => 2,

Yes, you need to increase read_timeout and timeout . 是的,您需要增加read_timeouttimeout The error is clear, you don't have enough time to get the response (the server is slow, network or something else, doesn't matter). 错误很明显,您没有足够的时间来获取响应(服务器很慢,网络或其他原因都没有关系)。

If it's possible, increasing the timeouts is the easiest way. 如果可能的话,增加超时是最简单的方法。

If the server supports pagination, it's a better way to request the data part by part. 如果服务器支持分页,则这是一种更好地部分请求数据的更好方法。

Also you can use async queries in Guzzle and send something to your end user while you are waiting for the response from the API. 您还可以在Guzzle中使用异步查询,并在等待来自API的响应时向最终用户发送一些内容。

simply add this in your composer, worked for me !只需将其添加到您的作曲家中,对我有用!

 "require": {
        "ext-curl": "*"
    },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WAMP/Wordpress - cURL 错误 28:操作在 10001 毫秒后超时,收到 0 个字节 - WAMP/Wordpress - cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received Wordpress/Godaddy - cURL 错误 28:操作在 10001 毫秒后超时,收到 0 个字节 - Wordpress/Godaddy - cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received cURL 错误 #:操作在 50007 毫秒后超时,收到 272389 个字节中的 30461 个 - cURL Error #:Operation timed out after 50007 milliseconds with 30461 out of 272389 bytes received LaravelFacebookSDK操作在0毫秒后超时,收到0个字节中的0个 - LaravelFacebookSDK Operation timed out after 0 milliseconds with 0 out of 0 bytes received php cURL操作在120308毫秒后超时,X收到-1个字节 - php cURL Operation timed out after 120308 milliseconds with X out of -1 bytes received cURL 错误 28:5001 毫秒后解析超时 - cURL error 28: Resolving timed out after 5001 milliseconds Curl 总是超时,操作在 30001 毫秒后超时,收到 0 个字节 - Curl always timeout, Operation timed out after 30001 milliseconds with 0 bytes received curl php操作在120000毫秒后超时,收到234570字节 - curl php Operation timed out after 120000 milliseconds with 234570 bytes received cURL 错误 28 - x 毫秒后连接超时 - cURL error 28 - Connection timed out after x milliseconds cURL:操作在0毫秒后超时 - cURL: Operation timed out after 0 milliseconds
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM