suppose PHP memory limit is set to 128M
now suppose you do
$v = "128 M worth of data";
will this cause a PHP out of memory error to occur?
suppose PHP memory limit is set to 128M
now suppose you do
$v = "128 M worth of data";
will this cause a PHP out of memory error to occur?
Yes it will fail with the following error, you can try it:
Fatal error: Allowed memory size of xxxxxx bytes exhausted (tried to allocate xxxxxxx bytes)
And that's the expected result, as the data for the string must be saved somewhere -> in memory ;)
Although there are several limits, I suppose you mean the "memory_limit" value you can set with ini_set
. Then the answers would actually be no.
If you set the value to the exact limit, you will be fine (if that is everything there is in your script). But the problem is when you use 1 byte more than that. So you can no longer do anything in your script. If you try to copy the value or do something with it, you will exceed the limit and it will break down. So its useless to have a string like that.
This question that was recently posted has some nice answers on it: memory-get-peak-usage-with-real-usage