3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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");
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.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 hhvm-3.12.0
10.09.2013 16:14:41 2,097,152 Starting 10.09.2013 16:14:41 2,097,152 filling 0 10.09.2013 16:14:41 2,097,152 filled 0 10.09.2013 16:14:41 2,097,152 unset 0 10.09.2013 16:14:41 2,097,152 filling 1 10.09.2013 16:14:41 2,097,152 filled 1 10.09.2013 16:14:41 2,097,152 unset 1 10.09.2013 16:14:41 2,097,152 filling 2 10.09.2013 16:14:41 2,097,152 filled 2 10.09.2013 16:14:41 2,097,152 unset 2 10.09.2013 16:14:41 2,097,152 filling 3 10.09.2013 16:14:41 2,097,152 filled 3 10.09.2013 16:14:41 2,097,152 unset 3 10.09.2013 16:14:41 2,097,152 filling 4 10.09.2013 16:14:41 2,097,152 filled 4 10.09.2013 16:14:41 2,097,152 unset 4 10.09.2013 16:14:41 2,097,152 filling 5 10.09.2013 16:14:41 4,194,304 filled 5 10.09.2013 16:14:41 4,194,304 unset 5 10.09.2013 16:14:41 4,194,304 filling 6 10.09.2013 16:14:41 4,194,304 filled 6 10.09.2013 16:14:41 4,194,304 unset 6 10.09.2013 16:14:41 4,194,304 filling 7 10.09.2013 16:14:41 4,194,304 filled 7 10.09.2013 16:14:41 4,194,304 unset 7 10.09.2013 16:14:41 4,194,304 filling 8 10.09.2013 16:14:41 4,194,304 filled 8 10.09.2013 16:14:41 4,194,304 unset 8 10.09.2013 16:14:41 4,194,304 filling 9 10.09.2013 16:14:41 4,194,304 filled 9 10.09.2013 16:14:41 4,194,304 unset 9 10.09.2013 16:14:41 4,194,304 filling 10 10.09.2013 16:14:41 4,194,304 filled 10 10.09.2013 16:14:41 4,194,304 unset 10 10.09.2013 16:14:41 4,194,304 filling 11 10.09.2013 16:14:41 4,194,304 filled 11 10.09.2013 16:14:41 4,194,304 unset 11 10.09.2013 16:14:41 4,194,304 filling 12 10.09.2013 16:14:41 6,291,456 filled 12 10.09.2013 16:14:41 6,291,456 unset 12 10.09.2013 16:14:41 6,291,456 filling 13 10.09.2013 16:14:41 6,291,456 filled 13 10.09.2013 16:14:41 6,291,456 unset 13 10.09.2013 16:14:41 6,291,456 filling 14 10.09.2013 16:14:41 6,291,456 filled 14 10.09.2013 16:14:41 6,291,456 unset 14 10.09.2013 16:14:41 6,291,456 filling 15 10.09.2013 16:14:41 6,291,456 filled 15 10.09.2013 16:14:41 6,291,456 unset 15 10.09.2013 16:14:41 6,291,456 filling 16 mallctl opt.prof: No such file or directory (2) Fatal error: request has exceeded memory limit in /in/B6BZC on line 46
Process exited with code 255.
Output for hhvm-3.10.0
10.09.2013 16:14:41 2,097,152 Starting 10.09.2013 16:14:41 2,097,152 filling 0 10.09.2013 16:14:41 2,097,152 filled 0 10.09.2013 16:14:41 2,097,152 unset 0 10.09.2013 16:14:41 2,097,152 filling 1 10.09.2013 16:14:41 2,097,152 filled 1 10.09.2013 16:14:41 2,097,152 unset 1 10.09.2013 16:14:41 2,097,152 filling 2 10.09.2013 16:14:41 2,097,152 filled 2 10.09.2013 16:14:41 2,097,152 unset 2 10.09.2013 16:14:41 2,097,152 filling 3 10.09.2013 16:14:41 2,097,152 filled 3 10.09.2013 16:14:41 2,097,152 unset 3 10.09.2013 16:14:41 2,097,152 filling 4 10.09.2013 16:14:41 2,097,152 filled 4 10.09.2013 16:14:41 2,097,152 unset 4 10.09.2013 16:14:41 2,097,152 filling 5 10.09.2013 16:14:41 4,194,304 filled 5 10.09.2013 16:14:41 4,194,304 unset 5 10.09.2013 16:14:41 4,194,304 filling 6 10.09.2013 16:14:41 4,194,304 filled 6 10.09.2013 16:14:41 4,194,304 unset 6 10.09.2013 16:14:41 4,194,304 filling 7 10.09.2013 16:14:41 4,194,304 filled 7 10.09.2013 16:14:41 4,194,304 unset 7 10.09.2013 16:14:41 4,194,304 filling 8 10.09.2013 16:14:41 4,194,304 filled 8 10.09.2013 16:14:41 4,194,304 unset 8 10.09.2013 16:14:41 4,194,304 filling 9 10.09.2013 16:14:41 4,194,304 filled 9 10.09.2013 16:14:41 4,194,304 unset 9 10.09.2013 16:14:41 4,194,304 filling 10 10.09.2013 16:14:41 6,291,456 filled 10 10.09.2013 16:14:41 6,291,456 unset 10 10.09.2013 16:14:41 6,291,456 filling 11 10.09.2013 16:14:41 6,291,456 filled 11 10.09.2013 16:14:41 6,291,456 unset 11 10.09.2013 16:14:41 6,291,456 filling 12 10.09.2013 16:14:41 6,291,456 filled 12 10.09.2013 16:14:41 6,291,456 unset 12 10.09.2013 16:14:41 6,291,456 filling 13 10.09.2013 16:14:41 6,291,456 filled 13 10.09.2013 16:14:41 6,291,456 unset 13 10.09.2013 16:14:41 6,291,456 filling 14 10.09.2013 16:14:41 6,291,456 filled 14 10.09.2013 16:14:41 6,291,456 unset 14 10.09.2013 16:14:41 6,291,456 filling 15 10.09.2013 16:14:41 6,291,456 filled 15 10.09.2013 16:14:41 6,291,456 unset 15 10.09.2013 16:14:41 6,291,456 filling 16 10.09.2013 16:14:41 8,388,608 filled 16 Fatal error: request has exceeded memory limit in /in/B6BZC on line 32
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.