- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 Laravel 项目中使用 Guzzle。当我向返回大量有效负载的 API 发出请求时,我遇到了内存崩溃。
我在 CURL.php
类的顶部有这个。我有使用 Guzzle 的 get()。
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;
}
...
}
当我在我的应用程序中这样调用它时,它会请求一个大的负载 (30000)
$url = 'http://site/api/account/30000';
$response = CURL::get($url)['data'];
我一直收到这个错误
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)
如何避免这种情况?
我应该增加这些设置吗?
'connect_timeout' => 2,
'read_timeout' => 2,
'timeout' => 2,
最佳答案
是的,你需要增加read_timeout
和timeout
。错误很明显,你没有足够的时间得到响应(服务器很慢,网络或其他什么的,无所谓)。
如果可能,增加超时是最简单的方法。
如果服务器支持分页,那么逐个请求数据是一种更好的方式。
您还可以在 Guzzle 中使用异步查询,并在等待 API 响应时向您的最终用户发送一些内容。
关于php - curl 错误 28 : Operation timed out after 2000 milliseconds with 7276200 out of 23000995 bytes received,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46897627/
我正在尝试使用 condition_variable_any::timed_wait() 当我将 boost::chrono::millisecond 传递给函数时,它无法编译: error: no
我正在像这样使用 boost::asio::deadline_timer 在 tcp socket 上的 async_read 操作之前设置一些超时。我正在使用 boost 1.61。 long ti
我需要在我的方法中执行某种“超时”或暂停 10 秒(10000 毫秒),但我不确定以下是否可行,因为我没有多线程。 Thread.Sleep(10000); 我将尝试使用当前代码,但如果有人能解释最佳
如何创建索引包含毫秒的xts对象?我在POSIXlt帮助页面上找不到任何格式规范,但indexFormat()中有%OS的reference。 更新 基于盖文动物园答案的xts示例: > option
无论时区如何,我都需要将毫秒转换为时间。下面是示例代码 我 := 1481462220 tm := 时间.Unix(i, 0) 当前时间。Unix 返回特定于我的机器区域的时间。因此,如果我更改机器的
假设我们有两个表: CREATE TABLE IF NOT EXISTS tech_time( ms_since_epoch BIGINT ); CREATE TABLE IF NOT EXI
我在数据库中有 start_time 和 end_time 列,其中包含毫秒值。 start_time > 2018 年 2 月 14 日星期三 11:00:00(真实日期)= 15185862000
我尝试执行多次登录(使用 TestNG),我的第一个 test1 通过了,但其余测试给出了一些错误,例如“元素当前不可见,因此可能无法与命令持续时间或超时交互:28 毫秒”。请解决我的问题 Strin
Date 类的 JavaDoc 指出 public Date(long date) Allocates a Date object and initializes it to represent th
我在我的程序中使用 MilliDTSC 类。我希望刷新率设置为 100ms 。我已经使用 javax.swing.Timer 在 100 毫秒后更新 GUI,但我的域轴在每毫秒后更新,因为单位是“毫秒
我遇到了一个小问题,我没有在网上找到合适的解决方案,因为我的问题对搜索引擎来说有点棘手。 关于 hibernate 节省毫秒的话题有很多。但我的问题是别的。 事实上,我有一个数据库,它像这样保存我的日
我希望将任意值从毫秒转换为秒,我的首选是 TimeUnit.MILLISECONDS.toSeconds。但是它返回一个长整数,因此将 1 毫秒转换为 0 秒而不是 0.001 秒。 阅读时the d
我正在深入研究 iOS 开发,并尝试在我的一个 View 中创建一个计数计时器。我有 NSTimer 代码计算出每 0.04 秒调用一次更新 UILabel 的选择器。我遇到问题的地方是当前时间的格式
目前我通过以下方式获取日期和时间: std::string isoString = boost::posix_time::to_iso_string(boost::posix_time::secon
在创建日志时,我正在使用 Datetime.Now.Millisecond。但我只有毫秒。我没有得到像 11/09/2015 10:59:48:936 这样的全职时间,而是只有 936。 我哪里错了?
具有 dateMillis 列的数据框,其中包含纪元的毫秒时间戳 In [5]: df.head(5) Out[5]: custId dateMillis 0
我想获取当前日期,时间以毫秒为单位归零。 例如,如果今天是中午 12:69,我想获取今天日期的时间(以毫秒为单位,没有时间)...意思是午夜刚过的时间(如果有效,则为 1 毫秒或 0)。 我正在使用
如何将给定的毫秒数(例如 125230.41294642858)解析为如下时间格式:分钟:秒? 最佳答案 var ms = 125230.41294642858, min = 0|(ms/100
能否告诉我如何在 PHP 中将 mm:ss 转换为毫秒。 $value = "10:10" $ms = ... 最佳答案 无需进行字符串转换或数组操作: sscanf($value, "%d:%d",
我正在尝试计算两天之间的天数差。由于某种原因,比较 01-03-2013 和 01-04-2013 给出结果 30,比较 01-03-2013 和 31-03-2013 也是如此 Calendar c
我是一名优秀的程序员,十分优秀!