[英]Laravel Guzzle Return error
我正在使用laravel 5.5.*
和guzzlehttp/guzzle ^6.3
。 我已经创建了(在同一个项目的API using laravel api.php
)和消费在同一项目(API using laravel web.php
)和给定的throttle 120 per second
。
一切都正常工作,但使用食尸鬼解析时突然出现以下错误
{
"error": "FatalErrorException",
"reason": "Allowed memory size of 536870912 bytes exhausted (tried to allocate 266342400 bytes)",
"code": 1,
"trace": []
}
使用XAMPP server
和memory_limit=2048M
。 如果我在浏览器中访问API,则加载正常
下方的大量解析代码
$client = new Client([
'base_uri' => env('API_URL'),
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'],
'debug' => true,
]);
拜托,有人帮助我,我该如何解决? 即使清除缓存也生成了新密钥
您的脚本上存在内存泄漏,而该泄漏通常是由于在while loop
重新定义枪口while loop
,请尝试使用memory_get_usage
调试脚本的内存使用情况。
并且不要在循环中定义类,在这种情况下,必须在循环之外使用适配器,如下所示:
$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);
}
编辑 :
您可以调试更多的内存消耗者:
编辑2 :
作为新的注释,请在调用api之前和之后memory_get_usage
通过memory_get_usage
函数查看内存使用情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.