dongpengqin3898 2015-01-21 13:22
浏览 355
已采纳

Guzzle:未捕获的异常和内存泄漏

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
Guzzle stack trace
Memory leak
Memory leak

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

  • 写回答

1条回答 默认 最新

  • dsgm5631 2015-01-21 13:51
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?