@ 2013-09-10T14:14:41Z <?php
// This is a proof-of-concept for the PHP-Memory-Bug.
// This is a well known PHP-Behavior, this script will test if this bug
// can be solved using "array-key-recycling".
// Switch this to proof
//$bLinear = FALSE; // Array-Keys are recycled
$bLinear = TRUE; // Array-Keys just increment -> Bug!
// Some Constants
$loops = 1000;
$start = 0;
$size = 1000;
$payload = "testing...";
$mem_limit = "5M";
// Set Memory-Limit, define memory_get_usage for older versions
ini_set("memory_limit",$mem_limit);
if(!function_exists("memory_get_usage")){
function memory_get_usage() {
$output = Array();
$pid = getmypid();
exec("ps -o rss -p $pid", $output);
return $output[1] *1024;
}
}
// Output-Function
function sEcho($message = ""){
echo date("d.m.Y H:i:s")." ".number_format(memory_get_usage())." ".$message."\n";
}
sEcho("Starting");
// Main loop
for($k=0;$k<$loops;$k++){
// Recycle or use new array-key
$multiplier = 1;
if($bLinear) $multiplier = $k;
// Get some Data - i.e. from MySQL
$arData = Array();
sEcho("filling ".$k);
for($i=$start*$multiplier;$i<($size*$multiplier)+$size;$i++){
$arData["a"][$i]["c"] = $payload;
$arData["b"][$i]["d"] = $payload;
}
sEcho("filled ".$k);
// Do Some Stuff...
// Free data again
unset($arData); // This will not free the used array-keys.
sEcho("unset ".$k);
}
sEcho("Done");
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.2.0 10.09.2013 16:14:41 390,048 Starting
10.09.2013 16:14:41 390,120 filling 0
10.09.2013 16:14:41 1,216,336 filled 0
10.09.2013 16:14:41 390,112 unset 0
10.09.2013 16:14:41 390,120 filling 1
10.09.2013 16:14:41 2,033,872 filled 1
10.09.2013 16:14:41 390,112 unset 1
10.09.2013 16:14:41 390,120 filling 2
10.09.2013 16:14:41 2,916,944 filled 2
10.09.2013 16:14:41 390,112 unset 2
10.09.2013 16:14:41 390,120 filling 3
10.09.2013 16:14:41 3,668,944 filled 3
10.09.2013 16:14:41 390,112 unset 3
10.09.2013 16:14:41 390,120 filling 4
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 266240 bytes) in /in/B6BZC on line 48
Process exited with code 255 . Output for 7.1.7 10.09.2013 16:14:41 353,600 Starting
10.09.2013 16:14:41 353,672 filling 0
10.09.2013 16:14:41 1,179,888 filled 0
10.09.2013 16:14:41 353,664 unset 0
10.09.2013 16:14:41 353,672 filling 1
10.09.2013 16:14:41 1,997,424 filled 1
10.09.2013 16:14:41 353,664 unset 1
10.09.2013 16:14:41 353,672 filling 2
10.09.2013 16:14:41 2,880,496 filled 2
10.09.2013 16:14:41 353,664 unset 2
10.09.2013 16:14:41 353,672 filling 3
10.09.2013 16:14:41 3,632,496 filled 3
10.09.2013 16:14:41 353,664 unset 3
10.09.2013 16:14:41 353,672 filling 4
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 266240 bytes) in /in/B6BZC on line 48
Process exited with code 255 . Output for 7.1.5 - 7.1.6 10.09.2013 16:14:41 354,080 Starting
10.09.2013 16:14:41 354,152 filling 0
10.09.2013 16:14:41 1,180,368 filled 0
10.09.2013 16:14:41 354,144 unset 0
10.09.2013 16:14:41 354,152 filling 1
10.09.2013 16:14:41 1,997,904 filled 1
10.09.2013 16:14:41 354,144 unset 1
10.09.2013 16:14:41 354,152 filling 2
10.09.2013 16:14:41 2,880,976 filled 2
10.09.2013 16:14:41 354,144 unset 2
10.09.2013 16:14:41 354,152 filling 3
10.09.2013 16:14:41 3,632,976 filled 3
10.09.2013 16:14:41 354,144 unset 3
10.09.2013 16:14:41 354,152 filling 4
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 266240 bytes) in /in/B6BZC on line 48
Process exited with code 255 . Output for 7.1.0 10.09.2013 16:14:41 353,592 Starting
10.09.2013 16:14:41 353,664 filling 0
10.09.2013 16:14:41 1,179,880 filled 0
10.09.2013 16:14:41 353,656 unset 0
10.09.2013 16:14:41 353,664 filling 1
10.09.2013 16:14:41 1,997,416 filled 1
10.09.2013 16:14:41 353,656 unset 1
10.09.2013 16:14:41 353,664 filling 2
10.09.2013 16:14:41 2,880,488 filled 2
10.09.2013 16:14:41 353,656 unset 2
10.09.2013 16:14:41 353,664 filling 3
10.09.2013 16:14:41 3,632,488 filled 3
10.09.2013 16:14:41 353,656 unset 3
10.09.2013 16:14:41 353,664 filling 4
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 266240 bytes) in /in/B6BZC on line 48
Process exited with code 255 . Output for 7.0.20 10.09.2013 16:14:41 353,616 Starting
10.09.2013 16:14:41 353,744 filling 0
10.09.2013 16:14:41 1,179,904 filled 0
10.09.2013 16:14:41 353,680 unset 0
10.09.2013 16:14:41 353,744 filling 1
10.09.2013 16:14:41 1,997,440 filled 1
10.09.2013 16:14:41 353,680 unset 1
10.09.2013 16:14:41 353,744 filling 2
10.09.2013 16:14:41 2,880,512 filled 2
10.09.2013 16:14:41 353,680 unset 2
10.09.2013 16:14:41 353,744 filling 3
10.09.2013 16:14:41 3,632,512 filled 3
10.09.2013 16:14:41 353,680 unset 3
10.09.2013 16:14:41 353,744 filling 4
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 266240 bytes) in /in/B6BZC on line 48
Process exited with code 255 . Output for 7.0.0 - 7.0.14 10.09.2013 16:14:41 353,608 Starting
10.09.2013 16:14:41 353,736 filling 0
10.09.2013 16:14:41 1,179,896 filled 0
10.09.2013 16:14:41 353,672 unset 0
10.09.2013 16:14:41 353,736 filling 1
10.09.2013 16:14:41 1,997,432 filled 1
10.09.2013 16:14:41 353,672 unset 1
10.09.2013 16:14:41 353,736 filling 2
10.09.2013 16:14:41 2,880,504 filled 2
10.09.2013 16:14:41 353,672 unset 2
10.09.2013 16:14:41 353,736 filling 3
10.09.2013 16:14:41 3,632,504 filled 3
10.09.2013 16:14:41 353,672 unset 3
10.09.2013 16:14:41 353,736 filling 4
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 266240 bytes) in /in/B6BZC on line 48
Process exited with code 255 . Output for 5.6.0 - 5.6.28 10.09.2013 16:14:41 225,080 Starting
10.09.2013 16:14:41 225,608 filling 0
10.09.2013 16:14:41 1,026,720 filled 0
10.09.2013 16:14:41 225,520 unset 0
10.09.2013 16:14:41 225,744 filling 1
10.09.2013 16:14:41 1,827,208 filled 1
10.09.2013 16:14:41 225,520 unset 1
10.09.2013 16:14:41 225,744 filling 2
10.09.2013 16:14:41 2,645,416 filled 2
10.09.2013 16:14:41 225,520 unset 2
10.09.2013 16:14:41 225,744 filling 3
10.09.2013 16:14:41 3,430,024 filled 3
10.09.2013 16:14:41 225,520 unset 3
10.09.2013 16:14:41 225,744 filling 4
10.09.2013 16:14:41 4,279,440 filled 4
10.09.2013 16:14:41 225,520 unset 4
10.09.2013 16:14:41 225,744 filling 5
10.09.2013 16:14:41 5,063,520 filled 5
10.09.2013 16:14:41 225,520 unset 5
10.09.2013 16:14:41 225,744 filling 6
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 64 bytes) in /in/B6BZC on line 47
Process exited with code 255 . Output for 5.5.0 - 5.5.38 10.09.2013 16:14:41 225,088 Starting
10.09.2013 16:14:41 225,600 filling 0
10.09.2013 16:14:41 1,026,744 filled 0
10.09.2013 16:14:41 225,512 unset 0
10.09.2013 16:14:41 225,736 filling 1
10.09.2013 16:14:41 1,827,200 filled 1
10.09.2013 16:14:41 225,512 unset 1
10.09.2013 16:14:41 225,736 filling 2
10.09.2013 16:14:41 2,644,928 filled 2
10.09.2013 16:14:41 225,512 unset 2
10.09.2013 16:14:41 225,736 filling 3
10.09.2013 16:14:41 3,429,400 filled 3
10.09.2013 16:14:41 225,512 unset 3
10.09.2013 16:14:41 225,736 filling 4
10.09.2013 16:14:41 4,279,136 filled 4
10.09.2013 16:14:41 225,512 unset 4
10.09.2013 16:14:41 225,736 filling 5
10.09.2013 16:14:41 5,063,408 filled 5
10.09.2013 16:14:41 225,512 unset 5
10.09.2013 16:14:41 225,736 filling 6
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 72 bytes) in /in/B6BZC on line 47
Process exited with code 255 . Output for 5.4.0 - 5.4.45 10.09.2013 16:14:41 225,608 Starting
10.09.2013 16:14:41 226,120 filling 0
10.09.2013 16:14:41 1,027,264 filled 0
10.09.2013 16:14:41 226,032 unset 0
10.09.2013 16:14:41 226,256 filling 1
10.09.2013 16:14:41 1,827,664 filled 1
10.09.2013 16:14:41 226,032 unset 1
10.09.2013 16:14:41 226,256 filling 2
10.09.2013 16:14:41 2,645,840 filled 2
10.09.2013 16:14:41 226,032 unset 2
10.09.2013 16:14:41 226,256 filling 3
10.09.2013 16:14:41 3,429,568 filled 3
10.09.2013 16:14:41 226,032 unset 3
10.09.2013 16:14:41 226,256 filling 4
10.09.2013 16:14:41 4,279,440 filled 4
10.09.2013 16:14:41 226,032 unset 4
10.09.2013 16:14:41 226,256 filling 5
10.09.2013 16:14:41 5,063,736 filled 5
10.09.2013 16:14:41 226,032 unset 5
10.09.2013 16:14:41 226,256 filling 6
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 64 bytes) in /in/B6BZC on line 48
Process exited with code 255 . Output for 5.3.11 - 5.3.29 10.09.2013 16:14:41 632,680 Starting
10.09.2013 16:14:41 633,272 filling 0
10.09.2013 16:14:41 1,450,368 filled 0
10.09.2013 16:14:41 633,104 unset 0
10.09.2013 16:14:41 633,416 filling 1
10.09.2013 16:14:41 2,266,840 filled 1
10.09.2013 16:14:41 633,104 unset 1
10.09.2013 16:14:41 633,416 filling 2
10.09.2013 16:14:41 3,102,832 filled 2
10.09.2013 16:14:41 633,104 unset 2
10.09.2013 16:14:41 633,416 filling 3
10.09.2013 16:14:41 3,903,720 filled 3
10.09.2013 16:14:41 633,104 unset 3
10.09.2013 16:14:41 633,416 filling 4
10.09.2013 16:14:41 4,769,296 filled 4
10.09.2013 16:14:41 633,104 unset 4
10.09.2013 16:14:41 633,416 filling 5
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 72 bytes) in /in/B6BZC on line 48
Process exited with code 255 . Output for 5.3.0 - 5.3.10 10.09.2013 16:14:41 632,544 Starting
10.09.2013 16:14:41 633,136 filling 0
10.09.2013 16:14:41 1,450,240 filled 0
10.09.2013 16:14:41 632,968 unset 0
10.09.2013 16:14:41 633,280 filling 1
10.09.2013 16:14:41 2,266,744 filled 1
10.09.2013 16:14:41 632,968 unset 1
10.09.2013 16:14:41 633,280 filling 2
10.09.2013 16:14:41 3,101,576 filled 2
10.09.2013 16:14:41 632,968 unset 2
10.09.2013 16:14:41 633,280 filling 3
10.09.2013 16:14:41 3,902,352 filled 3
10.09.2013 16:14:41 632,968 unset 3
10.09.2013 16:14:41 633,280 filling 4
10.09.2013 16:14:41 4,768,272 filled 4
10.09.2013 16:14:41 632,968 unset 4
10.09.2013 16:14:41 633,280 filling 5
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 71 bytes) in /in/B6BZC on line 48
Process exited with code 255 . preferences:dark mode live preview
154.4 ms | 402 KiB | 161 Q