php数组的限制于memory_limit的关系
前几天在服务器上处理一个大文件时,遇到了一个问题
<br /> PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 10255856 bytes) in /usr/local/asg/www/scripts/sync.php on line 641<br />
<br /> $arr = array();<br /> for($i=0;$i=1590000;$i++) {<br /> $arr[] = $i;<br /> }<br /> <br /> echo count($arr);<br />
<br /> ; Maximum amount of memory a script may consume (128MB)<br /> ; http://php.net/memory-limit<br /> memory_limit = 128M<br />
<br /> Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes) in D:\server\www\02\array.php on line 5<br />
<br /> $arr = array();<br /> <br /> for($i=0;$i<1550000;$i++) {<br /> $arr[] = $i;<br /> }<br /> <br /> <br /> echo count($arr);<br />
<br /> ; Maximum amount of memory a script may consume (128MB)<br /> ; http://php.net/memory-limit<br /> memory_limit = 512M<br />
$t = 0;<br /> echo memory_get_usage() - $t, ' ',$t = memory_get_usage(), PHP_EOL;<br /> $a = array();<br /> echo memory_get_usage() - $t, ' ', $t = memory_get_usage(), PHP_EOL;<br /> $a[] = 1;<br /> echo memory_get_usage() - $t, ' ', $t = memory_get_usage(), PHP_EOL;<br /> $a[] = 2;<br /> echo memory_get_usage() - $t, ' ', $t = memory_get_usage(), PHP_EOL;<br /> $a[] = 3;<br /> echo memory_get_usage() - $t, ' ', $t = memory_get_usage(), PHP_EOL;<br />