Guzzle:未捕获的异常&内存泄漏 [英] Guzzle: Uncaught exception & memory leak

查看:1790
本文介绍了Guzzle:未捕获的异常&内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Guzzle 时遇到了奇怪的问题



当我试图模拟一个错误的请求(例如返回一个状态代码404的请求)Guzzle抛出一个ClientException包含为什么该请求失败的所有细节。



当我尝试捕获这个异常时,我的脚本退出时出现致命错误,说明我没有捕获异常,它显示一个XDebug跟踪,说明我有一个内存



我的代码如下所示:

注意: httpClient是GuzzleHttp / CLient的有效实例。

  $ request = $ this-> httpClient-> createRequest(
'GET',
'/templates/'.$id
);

try {
$ response = $ this-> httpClient-> send($ request);
} catch(\Exception $ exception){
die('exception occured');
}

我最终得到的错误如下:

Guzzle堆栈跟踪



内存泄漏

<

解决方案

有没有人会建议什么可能导致这个未被捕获的异常+

您的 XDebug 想要消耗的内存超过定义的上限



您的上限是: 512MO for A Script

您的 XDebug 想要消费: 652MO



您有两个解决方案可解决此技术问题

1 - 更新您的 php.ini => memory_limit = 768M ,然后重新启动服务器

2 - 在 PHP 脚本中将此行代码放在顶部:

  ini_set(memory_limit,768M); 

现在你必须完全确定这个内存泄漏不会在你的生产环境中发生, strong> XDebug


I'm having weird issues while using Guzzle

When I try to simulate an erroneous request (e.g. a request which returns a status code 404) Guzzle throws a ClientException containing all the details of why that request failed.

When I try to catch this exception my script exits with a fatal error stating that I didn't catch the exception and it shows an XDebug trace stating that I had a memory leak somehow.

My code looks like this:
Note: httpClient is a valid instance of GuzzleHttp/CLient.

$request  = $this->httpClient->createRequest(
    'GET',
    '/templates/'.$id
);

try {
    $response = $this->httpClient->send($request);
} catch (\Exception $exception) {
    die('exception occured');
}

The error I end up with is the following:
Guzzle stack trace

Memory leak

Does someone have a suggestion to what might cause this uncaught exception + leak?

解决方案

Your XDebug wants to consume more memory than the defined limit

Your limit is : 512MO for A Script
Your XDebug wants to consume : 652MO

You have 2 solutions to resolve this technical issue
1 - Update your php.ini => memory_limit = 768M and after that restart your server
2 - In your PHP script put this line code on top :

ini_set("memory_limit","768M");

Now you must be completely sure that this memory leak will not happend in your production environment, by disabling XDebug

这篇关于Guzzle:未捕获的异常&amp;内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆