3v4l.org

run code in 300+ PHP versions simultaneously
<?php set_time_limit(0); ### Helpers: function print_mem() { /* Currently used memory */ $mem_usage = memory_get_usage(); /* Peak memory usage */ $mem_peak = memory_get_peak_usage(); echo " " . 'The script is now using: ' . $mem_usage . " B of memory.\n"; echo " " . 'The script is now using: ' . round($mem_usage / 1024) . " KB of memory.\n"; echo " " . "Peak usage: " . round($mem_peak / 1024) . " KB of memory.\n"; } function get_formatted_microtime($time) { $to_format = DateTime::createFromFormat('U.u', sprintf("%.6F", $time)); $formatted = $to_format->format("Y-m-d H:i:s.u"); return $formatted; } ### Load Config: $time_start = microtime(true); // Loading configuration $config = parse_ini_file("config.ini", true); $time_end = microtime(true); $time = ($time_end - $time_start) * 1000; ### Merge CLI parameters into $_GET: if (isset($config['common-parameters'])) { foreach($config['common-parameters'] as $key => $value) { if (!isset($_GET[$key])) { $_GET[$key] = $value; } } } if (!empty($argv)) { parse_str(implode('&', array_slice($argv, 1)), $cli_arguments); $_GET = array_merge($_GET, $cli_arguments); } ### if (empty($argv)) { echo "<pre>\n"; } ### Connect to the database: $iteration = 0; $number_of_iterations = (int) $_GET['number_of_iterations']; while (true) { $iteration++; ### Actual Connection Time: $connection_attempt_start = microtime(true); $connection_attempt_start_formatted = get_formatted_microtime($connection_attempt_start); $was_connection_successful = false; try { echo "Before PDO Connection Attempt:\n"; print_mem(); // Creating MySQL Connection: $port = (int) $config['database']['port']; $dsn = "mysql:host={$config['database']['host']};dbname={$config['database']['database']};port={$port}"; $options = []; if ((bool) $config['database']['use_ssl']) { $options[PDO::MYSQL_ATTR_SSL_CA] = $config['ca_root_path']; } $pdo = new PDO($dsn, $config['database']['username'], $config['database']['password'], $options); $was_connection_successful = true; } catch (PDOException $e) { echo $e->code . ' ' . $e->message . "\n"; $was_connection_successful = false; } echo "After PDO Connection Attempt:\n"; print_mem(); $connection_attempt_end = microtime(true); $connection_attempt_end_formatted = get_formatted_microtime($connection_attempt_end); $connection_time = ($connection_attempt_end - $connection_attempt_start) * 1000; if ((bool)$_GET['show_output']) { if ($was_connection_successful) { echo "{$iteration}. Connected to database ({$config['database']['host']}) in $connection_time milliseconds.\n"; } else { echo "{$iteration}. Connection attempt to database ({$config['database']['host']}) failed after $connection_time milliseconds. Sleeping for 3 seconds.\n"; sleep(3); } } unset($pdo); if ($number_of_iterations !== 0 && $iteration >= $number_of_iterations) { break; } if (isset($_GET['iteration_delay']) && $_GET['iteration_delay'] > 0) { sleep((int) $_GET['iteration_delay']); } echo "Iteration finished: \n"; print_mem(); } if (empty($argv)) { echo "\n</pre>"; }
Output for 8.2.7
Warning: parse_ini_file(): open_basedir restriction in effect. File(config.ini) is not within the allowed path(s): (/tmp:/in:/etc) in /in/BOnq5 on line 33 Warning: parse_ini_file(config.ini): Failed to open stream: Operation not permitted in /in/BOnq5 on line 33 Warning: Undefined array key "number_of_iterations" in /in/BOnq5 on line 62 Before PDO Connection Attempt: The script is now using: 406024 B of memory. The script is now using: 397 KB of memory. Peak usage: 431 KB of memory. Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 79 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 79 Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 80 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 80 Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 80 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 80 Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 83 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 83 Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 87 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 87 Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 87 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 87 Fatal error: Uncaught Error: Cannot access protected property PDOException::$code in /in/BOnq5:92 Stack trace: #0 {main} thrown in /in/BOnq5 on line 92
Process exited with code 255.
Output for 8.1.8
Warning: parse_ini_file(): open_basedir restriction in effect. File(config.ini) is not within the allowed path(s): (/tmp:/in:/etc) in /in/BOnq5 on line 33 Warning: parse_ini_file(config.ini): Failed to open stream: Operation not permitted in /in/BOnq5 on line 33 Warning: Undefined array key "number_of_iterations" in /in/BOnq5 on line 62 Before PDO Connection Attempt: The script is now using: 406528 B of memory. The script is now using: 397 KB of memory. Peak usage: 432 KB of memory. Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 79 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 79 Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 80 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 80 Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 80 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 80 Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 83 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 83 Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 87 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 87 Warning: Trying to access array offset on value of type bool in /in/BOnq5 on line 87 Warning: Trying to access array offset on value of type null in /in/BOnq5 on line 87 Fatal error: Uncaught Error: Cannot access protected property PDOException::$code in /in/BOnq5:92 Stack trace: #0 {main} thrown in /in/BOnq5 on line 92
Process exited with code 255.
Output for 7.3.20
Warning: parse_ini_file(): open_basedir restriction in effect. File(config.ini) is not within the allowed path(s): (/tmp:/in:/etc) in /in/BOnq5 on line 33 Warning: parse_ini_file(config.ini): failed to open stream: Operation not permitted in /in/BOnq5 on line 33 Notice: Undefined index: number_of_iterations in /in/BOnq5 on line 62 Before PDO Connection Attempt: The script is now using: 403304 B of memory. The script is now using: 394 KB of memory. Peak usage: 428 KB of memory. Fatal error: Uncaught Error: Cannot access protected property PDOException::$code in /in/BOnq5:92 Stack trace: #0 {main} thrown in /in/BOnq5 on line 92
Process exited with code 255.

preferences:
68.12 ms | 412 KiB | 5 Q