Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KonScyence's avatar

Not ennough memory

Hello, for some reason, for a simple mysql query, I do not have enough memory, while it always works. I must have an error in my request.

Model:

$groups = DB::table('group')
      ->join('organisation', 'group.oid', '=', 'organisation.oid');
    if(Input::get('search')){
      $groups->where('group.group_name', 'LIKE', '%'.$search.'%')
    }
    if($oid!='0'){
        $groups->where('group.oid', '=', $oid);
     }
      $groups->offset($limit)
      ->limit(30)
      ->get();
return $groups;

Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 67112960 bytes)

Best regards

0 likes
10 replies
Snapey's avatar

are you sure its this query? It seems reasonable.

try dd($groups) immediately after the ->get()

Snapey's avatar

you answered the question. If dd was reached then its not the sql query that is giving your out of memory issue

What do you do next, or say where the error occurs

KonScyence's avatar

If I remove all condition to do a simple query like that it's working:

$groups = DB::table('org_group')
      ->join('organisation', 'org_group.oid', '=', 'organisation.oid');
      ->offset($limit)
      ->limit(30)
      ->get()
      ->toArrays();

But I need the condition... Do you have a solution ?

Best regards

KonScyence's avatar

@Snapey Ok... but if I do print_r($groups); exit; right after the get, it's showing the error...

Snapey's avatar

do you have a with statement in your models.?

KonScyence's avatar

It's a foreach in a view, I will try to find the solution

Please or to participate in this conversation.