Guzzle: Uncaught exception & memory leak

2019-08-05 23:19发布

问题:

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