Memory limit exceeded with PHP foreach

I am trying to execute many thousands of elements in an array, perform some operations and save some values ​​in mysql table.

However, as we go through the loop, memory usage is constantly growing until we finish the memory specified in php.ini, which is pretty fast.

I tried using unset by setting the variables to null and looking at the garbage collection, but nothing has an effect.

Is there a more efficient way that I can scroll through these elements (i.e. therefore memory usage is not constantly growing).

Below is a simplified example of what I am doing.

foreach ($subscribers as $subscriber)
{
    $member = new Member($subscriber['id']);
    if ($member['id'] > 0)
    {
        $bulletin = Bulletin::getCustomBulletin($member['id']);

        Bulletin::compileBulletin($member['email'], time(), $bulletin['title'], $bulletin['content']);

        echo $member['email'] . "\n";
        echo memory_get_usage() . "\n";
    }
}

This leads to the following results:

an@email.com
11336688
an@email.com
12043640
an@email.com
12749952
+3
source share
3 answers

Is the $suscribersresult of a database query?

, : , .

.

. : " " ?

+1

foreach ( , ). , . , IDE, . , memory_get_usage(), , , , .

, xdebug.

0

, , , , Member , :

- , , . , , - , - .

0

All Articles