Guzzle: Uncaught exception & memory leak

落爺英雄遲暮 提交于 2019-12-24 12:41:31

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/28068339/guzzle-uncaught-exception-memory-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!