tried to allocate 超大内存
本帖最后由 liaow10 于 2018-8-6 17:59 编辑项目偶尔会出现这种报错:
Severity:Error --> Allowed memory size of 134217728 bytes exhausted (tried to allocate 140015415477232 bytes) Unknown 0
Traceback: Extra: ["\/module-switch","params:"]
Severity:Error --> Allowed memory size of 134217728 bytes exhausted (tried to allocate 140548902478832 bytes) Unknown 0
Traceback: Extra: ["\/user-allfriends","params:"]
Severity:Error --> Allowed memory size of 134217728 bytes exhausted (tried to allocate 139702872970224 bytes) Unknown 0
Traceback: Extra: ["\/user-else-detail\/2256941804","params:"]
下面的那个 Extra 内容是我自己添加的,为了追查为什么会出现申请超大内存的问题,把请求协议和参数打了出来,结果还是没有发现什么蛛丝马迹,请问大佬们,这个是什么原因呢?
用的是 CI 3.1.0,拿第一个协议内容来举例子:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once(APPPATH . 'controllers/BaseController.php');
class ModuleSwitch extends BaseController {
function __construct(){
parent::__construct();
}
private function get_switch_redis()
{
require_once(APPPATH . 'libraries/RedisExtra.php');
return new RedisExtra('xxx');
}
public function get_status()
{
$redis = $this->get_switch_redis();
$values = $redis->hgetall('MODULE_SWITCH');
$status = array();
if ($values) {
foreach ($values as $key => $value) {
$status[$key] = (boolean)$value;
}
}
if (empty($status))
$status = (object)$status;
self::_makeResponse(RETURN_OK, $status);
}
}
别沉了啊,Hex大神! 人工顶 是不是一次取出了太多的数据?有可能把所有数据都取出来放内存里了,所以内存超了。 一般这种问题就是拿到测试环境上逐行打断点,最好能复现出来
可能原因就是$redis->hgetall('MODULE_SWITCH');,这里是否是一次取大量的数据??
页:
[1]