I am getting a PHP memory exhausted error even though the memory_limit is set to “-1” using “ini_set(“memory_limit”,”-1”); Tracing down the exact location where the issue is, I get to the “getAllMembers” function. There are more than 100k users in the site where this error is occurring. Error occurs when the super admin logs in to control panel and navigates to “Tool”->”utilities” area which has the “communication” or “email” form.
Could you suggest what could be going wrong?
Thanks.
File: system/ee/ExpressionEngine/Model/Role/Role.php Original Code: public function getAllMembers() { $members = array_replace($this->Members->indexBy(‘member_id’), $this->PrimaryMembers->indexBy(‘member_id’)); foreach ($this->RoleGroups as $role_group) { foreach ($role_group->Members as $member) { $members[$member->member_id] = $member; } } return new Collection($members); }
Altered function (obviously, the functionality is changed… ) that gets rid of the error: public function getAllMembers() { if ($this->role_id!=5) $members = array_replace($this->Members->indexBy(‘member_id’), $this->PrimaryMembers->indexBy(‘member_id’)); else $members = $this->Members->indexBy(‘member_id’); // $members = $this->PrimaryMembers->indexBy(‘member_id’); // using this code causes out of memory error
foreach ($this->RoleGroups as $role_group) {
foreach ($role_group->Members as $member) {
$members[$member->member_id] = $member;
}
} return new Collection($members); }
Sorry for the garbling of text. I tried to edit, but the edit icon takes to a page where I can only do a new post. Here is the code again.
File: system/ee/ExpressionEngine/Model/Role/Role.php Original Code:
public function getAllMembers() {
$members = array_replace($this->Members->indexBy(‘member_id’), $this->PrimaryMembers->indexBy(‘member_id’));
foreach ($this->RoleGroups as $role_group) {
foreach ($role_group->Members as $member) {
$members[$member->member_id] = $member;
}
}
return new Collection($members);
}
Altered function (obviously, the functionality is changed… ) that gets rid of the error:
public function getAllMembers() {
if ($this->role_id!=5)
$members = array_replace($this->Members->indexBy(‘member_id’), $this->PrimaryMembers->indexBy(‘member_id’));
else
$members = $this->Members->indexBy(‘member_id’);
// $members = $this->PrimaryMembers->indexBy(‘member_id’); // using this code causes out of memory error
foreach ($this->RoleGroups as $role_group) {
foreach ($role_group->Members as $member) {
$members[$member->member_id] = $member;
}
}
return new Collection($members);
}
Hi Robin, here is the error message I get. I have allocated 1GB RAM to each PHP process, which is a way more than necessary. If I allocated more, it will take that up also.
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in <base-path>/system/ee/legacy/database/DB_result.php on line 84
It seems that the issue is that the code is trying to load all 125k+ rows from members table and then organising the data in RAM… this is likely what is causing the memory to be exhausted.
Thank.
I have tried with 2G allocation to each PHP and the script times out.
The issue is with this call: $members = $this->PrimaryMembers->indexBy(‘member_id’);
This “$this->PrimaryMembers” is where things go south. In the update code (in pull request), there is a similar code “$role->PrimaryMembers->” where the code is failing. The fix undoes the “workaround” that is mentioned in the original posting.
Thanks.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.