3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestFixedArray extends SplFixedArray { private $_elements; public function __sleep() { $arr = (array)$this; unset($arr["\0TestFixedArray\0_elements"]); $this->_elements = $arr; $this->setSize(0); $arr = null; return array('_elements'); } public function __wakeup() { $size = count($this->_elements); $this->setSize($size); for($i = 0; $i < $size; $i++) { $this[(int)$i] = (int)$this->_elements[$i]; } $this->_elements = null; unset($this->_elements); } } $n = 100000; $t = microtime(true); $m = memory_get_usage(true); if(file_exists('cache.txt')) { echo 'Unserialize' . PHP_EOL; $content = file_get_contents('cache.txt'); $a = igbinary_unserialize($content); //$a = unserialize($content); $content = null; } else { echo 'Serialize' . PHP_EOL; //$a = new SplFixedArray($n); $a = new TestFixedArray($n); //$a = array(); for($i = 0; $i < $n; $i++) { $a[(int)$i] = (int)$i; } if(!file_exists('cache.txt')) { var_dump('serialize'); //file_put_contents('cache.txt', serialize($a)); file_put_contents('cache.txt', igbinary_serialize($a)); } } echo 'Peak: ' . memory_get_peak_usage(true) . PHP_EOL; echo 'Usage: ' . (memory_get_usage(true) - $m) . PHP_EOL; echo 'Time: ' . (microtime(true) - $t) . PHP_EOL;
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
Warning: file_exists(): open_basedir restriction in effect. File(cache.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/1Oomf on line 34 Serialize Warning: file_exists(): open_basedir restriction in effect. File(cache.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/1Oomf on line 51 string(9) "serialize" Fatal error: Uncaught Error: Call to undefined function igbinary_serialize() in /in/1Oomf:54 Stack trace: #0 {main} thrown in /in/1Oomf on line 54
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Warning: file_exists(): open_basedir restriction in effect. File(cache.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/1Oomf on line 34 Serialize Warning: file_exists(): open_basedir restriction in effect. File(cache.txt) is not within the allowed path(s): (/tmp:/in:/etc) in /in/1Oomf on line 51 string(9) "serialize" Fatal error: Call to undefined function igbinary_serialize() in /in/1Oomf on line 54
Process exited with code 255.

preferences:
75.32 ms | 408 KiB | 5 Q