3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo sprintf("\n%.1fMB", memory_get_usage(true) / 1024 / 1024); // allocate a large byte string of around 5 MB $a = str_repeat("0", 5 * 1024 * 1024); echo sprintf("\n%.1fMB", memory_get_usage(true) / 1024 / 1024); // setting the memory limit lower than the current is accepted ini_set("memory_limit", "3M"); echo sprintf("\n%.1fMB", memory_get_usage(true) / 1024 / 1024); // further allocation beyond the limit $b = str_repeat("0", 5 * 1024 * 1024); echo sprintf("\n%.1fMB", memory_get_usage(true) / 1024 / 1024);
Output for 7.4.21, 8.0.8
2.0MB 7.0MB Warning: Failed to set memory limit to 3145728 bytes (Current memory usage is 7344128 bytes) in /in/egq60 on line 9 7.0MB 12.0MB
Output for 7.3.10 - 7.3.29, 7.4.0 - 7.4.20, 8.0.0 - 8.0.7
2.0MB 7.0MB 7.0MB 12.0MB
Output for 7.3.0 - 7.3.9
2.0MB 7.0MB 7.0MB Fatal error: Allowed memory size of 3145728 bytes exhausted (tried to allocate 5242912 bytes) in /in/egq60 on line 13
Process exited with code 255.

preferences:
46.22 ms | 462 KiB | 5 Q