[英]Laravel Guzzle Return error
I am using laravel 5.5.*
and guzzlehttp/guzzle ^6.3
. 我正在使用
laravel 5.5.*
和guzzlehttp/guzzle ^6.3
。 I have created APIs in the same project ( using laravel api.php
) and consuming API on the same project ( using laravel web.php
) and given throttle 120 per second
. 我已经创建了(在同一个项目的API
using laravel api.php
)和消费在同一项目(API using laravel web.php
)和给定的throttle 120 per second
。
everything was working properly but suddenly got following error while parsing using guzzle 一切都正常工作,但使用食尸鬼解析时突然出现以下错误
{
"error": "FatalErrorException",
"reason": "Allowed memory size of 536870912 bytes exhausted (tried to allocate 266342400 bytes)",
"code": 1,
"trace": []
}
Using XAMPP server
and memory_limit=2048M
. 使用
XAMPP server
和memory_limit=2048M
。 If I access API in the browser it loads fine 如果我在浏览器中访问API,则加载正常
Guzzle parsing code below 下方的大量解析代码
$client = new Client([
'base_uri' => env('API_URL'),
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'],
'debug' => true,
]);
Please, someone, help me how I can fix it? 拜托,有人帮助我,我该如何解决? even I cleared cache also generated a new key
即使清除缓存也生成了新密钥
You have a memory leak on your script that always became from redefining a guzzle in a while loop
, try using memory_get_usage
to debug the memory usage of your script . 您的脚本上存在内存泄漏,而该泄漏通常是由于在
while loop
重新定义枪口while loop
,请尝试使用memory_get_usage
调试脚本的内存使用情况。
And don't define a class in loops , in your situation that you must use a adapter outside of the loops , like this : 并且不要在循环中定义类,在这种情况下,必须在循环之外使用适配器,如下所示:
$adapter = new \GuzzleHttp\Adapter\Curl\MultiAdapter(
new \GuzzleHttp\Message\MessageFactory()
);
while (true) {
$client = new GuzzleHttp\Client(['adapter' => $adapter]);
$client->get('http://example.com/guzzle-server');
echo memory_get_usage() . "\n";
usleep(20000);
}
EDIT : 编辑 :
You can debug more on memory eaters : 您可以调试更多的内存消耗者:
Memprof is a php extension that helps finding those memory-eaters snippets, specially in object-oriented codes.
Memprof是php扩展,可帮助查找那些占用内存的代码段,特别是在面向对象的代码中。 [SOURCE]
[资源]
EDIT2 : 编辑2 :
As the new comments , try to see memory usage via memory_get_usage
function before & after calling your api . 作为新的注释,请在调用api之前和之后
memory_get_usage
通过memory_get_usage
函数查看内存使用情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.