PHP - Out of Memory while very simple loop, w/o object

Mickael_42

i have some trouble for a very simple loop because i goes out of memory and i really dont know why. Hope someone will be able to help me. Here is my code:

$full_list = array();
$fp = fopen($file_name, 'r');
while (($line = fgetcsv($fp, 0, $delimiter)) !== FALSE)
{
    $val = array_slice($line, 0, 1);
    $line = NULL;
    unset($line);
    if (in_array($val, $full_list) === FALSE)
        $full_list[] = $val;
    $val = NULL;
    unset($val);
}
fclose($fp);

I tried the $line = NULL && then unset it as u can see but even like that it doesnt work, if the file is too big i'll get out of memory... To be honest, i dont even understand why the memory even increase during the loop....

Maximilian Prepl

yes, you will always run out of memory, because, variable $full_list will always grow, till you will reach out of memory.

you need to do your stuff directly in while cycle.

and instead use array_slice($line, 0, 1) just use: $line[0]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related