Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP memory_get_peak_usage and ini_set('memory_limit', '-1')
    text
    copied!<p>I recently ran into memory allocation problems, so I started experimenting with the <code>ini_set('memory_limit', value);</code> directive where I tried to enter values incrementaly. Now, searching through the web (and SO) I found out that I can put <code>-1</code> as the <code>value</code>. So, I did and now the script runs fully to the end without breaking (before I used to get the memory allocation error). </p> <p>What I don't understand, however, is that given these two lines at the end of the script's file:</p> <pre><code>$mem = memory_get_peak_usage(true); echo "Peak mem. usage: &lt;b&gt;" . round($mem / 1024 / 10124, 2) . "&lt;/b&gt; MB"; </code></pre> <p>produce around <strong>10.8MB</strong> and when I look into the <code>/var/log/messages</code> I can see this line:</p> <pre><code>Nov 21 13:52:26 mail suhosin[1153]: ALERT-SIMULATION - script tried to increase memory_limit to 4294967295 bytes which is above the allowed value (attacker 'xx.xxx.xxx.xxx', file '/var/www/html/file.php', line 5) </code></pre> <p>which means the script tried to alocate <strong>4096MB</strong>!</p> <p>How can this be? And also, what interest me the most is why didn't the script execution stop in this case? Is it because of the <code>ini_set('memory_limit', '-1');</code>? I mean, I did read that putting <code>-1</code> as the <code>value</code> is not recomended and I know where the problem lies in the script (reading too big amount of data at once in the memory), and I will go and fix it with sequential reading, but I'm just baffled about these data differences, so I would be gratefull if someone can shed some light on it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload