Why does a simple PHP unset () memory test use twice as much memory in PHP 5.3?

I tested whether unset () affects memory while the script is running, to see if unset () or another known method, $ var = null is more efficient. unset () really affected the memory, but since I tested it on two different virtual hosts, I wondered why it takes twice as much memory for the same script? I suppose the answer is simple, but now it is slipping away from me. The script itself is below:

<?php $init=memory_get_usage(); $test=array(); for($i=0;$i<=100000;$i++){ $test[$i]=rand(0,10000000); } echo 'MEMORY CHANGE: '.((memory_get_usage()-$init)/1024/1024).'MB<br/>'; for($i=0;$i<=100000;$i++){ unset($test[$i]); } echo 'MEMORY CHANGE: '.((memory_get_usage()-$init)/1024/1024).'MB<br/>'; //output on PHP 3.2.5 virtualhost: //MEMORY CHANGE: 6.98558807373MB //MEMORY CHANGE: 0.500259399414MB //output on PHP 5.3.5 virtualhost //MEMORY CHANGE: 13.970664978MB //MEMORY CHANGE: 1.00063323975MB ?> 

Thanks!

+4
source share
1 answer

PHP 3.2.5? It is so old that it does not even reach the Stone Age. PHP guts have undergone a complete rewrite with the Zend engine, so although the language itself has remained relatively the same, you are comparing two different environments.

But in case the version number is a typo, perhaps it is a 32bit vs 64-bit host that doubles the size of int and can take into account your estimated difference 2 times.

+3
source

All Articles