3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Social network site where you can see a list of users and "follow" them. */ // setup the `Db` object: require_once 'lib/db.php'; // setup the `Session` object: require_once 'lib/session.php'; if (!Session::isLoggedIn()) { throw new Exception('You must be logged in to view this page'); } // display a user as html function displayUser ($user, $tag='div') { $full_name = $user->first_name . ' ' . $user->last_name; // get user's avatar from 3rd-party avatar service, based on which environment we're running in if (strpos($_SERVER['SERVER_NAME'], 'localhost') !== false) { $avatar_data = json_decode(file_get_contents('http://dev.avatars.com/user/' . $user->id)); } else { $avatar_data = json_decode(file_get_contents('http://www.avatars.com/user/' . $user->id)); } ?> <<?= $tag ?> class="user"> <a href="/users/<?= $user->id ?>"> <img src="<?= $avatar_data->url ?>"> <?= $full_name ?> </a> <a href="?follow=<?= $user->id ?>">Follow</a> </<?= $tag ?>> <?php } // check that a user ID is valid (must be a number) function validateUserId ($id) { if (!is_numeric($id)) { // log invalid user IDs to help us track down bugs. error_log("Invalid user id: {$id}"); return false; } return true; } // load the user's custom theme config $theme_filename = dirname(__FILE__) . 'themes/' . Session::getLoggedInUser()->theme_id . '.php'; if (file_exists($theme_filename)) { require $theme_filename; } // show all users if (isset($_GET['show-all'])) { echo '<ul>'; foreach (Db::getUsers() as $user) { displayUser($user, 'li'); } echo '</ul>'; } // show a single user else if (isset($_GET['id'])) { $id = $_GET['id']; if (!validateUserId($id)) throw new Exception('Please select a valid user ID'); $user = Db::getUserById($id); if (!$user) throw new Exception('Sorry, user not found'); displayUser($user); } // follow a user else if (isset($_GET['follow'])) { $id = $_GET['follow']; if (!validateUserId($id)) throw new Exception('Please select a valid user ID'); $user_to_follow = Db::getUserById($id); if (!$user_to_follow) throw new Exception('Sorry, user not found'); $current_user = Session::getLoggedInUser(); try { $current_user->follow($user_to_follow); } catch (Exception $e) { throw new Exception('Unable to follow at this time'); } // inform the user that they have a new follower. mail( $user_to_follow->email, 'You have a new follower!', "{$current_user->username} is now following you.", 'From: notifications@awesome-social-network.com' ); // also update the activity feed, so users can see what others are doing on the site. Db::updateActivityFeed(array( 'action' => 'follow', 'from' => $current_user->id, 'to' => $user_to_follow->id, 'timestamp' => time(), )); echo 'Followed! <a href="/">Return to home</a>'; } ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.0.120.0000.00713.50
8.0.110.0000.00713.46
8.0.100.0000.00813.53
8.0.90.0040.00413.41
8.0.80.0070.00013.55
8.0.70.0030.00313.48
8.0.60.0040.00413.50
8.0.50.0000.00713.54
8.0.30.0000.00713.48
8.0.20.0000.00713.44
8.0.10.0030.00313.56
8.0.00.0070.00013.43
7.4.250.0000.00713.32
7.4.240.0000.00613.34
7.4.230.0030.00313.35
7.4.220.0070.00013.25
7.4.210.0030.00313.27
7.4.200.0060.00013.36
7.4.190.0030.00313.38
7.4.180.0030.00313.43
7.4.160.0030.00313.39
7.4.150.0000.00613.34
7.4.140.0060.00013.25
7.4.130.0030.00313.21
7.4.120.0000.00613.22
7.4.110.0000.00613.26
7.4.100.0030.00313.34
7.4.90.0000.00613.29
7.4.80.0000.00613.22
7.4.70.0060.00013.03
7.4.60.0000.00713.03
7.4.50.0060.00012.95
7.4.40.0060.00013.06
7.4.30.0000.00613.18
7.4.20.0000.00613.24
7.4.10.0060.00013.05
7.4.00.0040.00914.27
7.3.310.0060.00013.15
7.3.300.0000.00713.31
7.3.290.0060.00013.27
7.3.280.0060.00013.14
7.3.270.0000.00613.21
7.3.260.0000.00513.21
7.3.250.0050.00013.33
7.3.240.0030.00313.31
7.3.230.0000.00813.33
7.3.220.0000.00713.12
7.3.210.0000.00613.15
7.3.200.0050.00013.07
7.3.190.0060.00013.29
7.3.180.0050.00013.10
7.3.170.0030.00313.24
7.3.160.0070.00013.21
7.3.150.0030.00313.25
7.3.140.0000.00513.27
7.3.130.0050.00013.27
7.3.120.0060.00614.08
7.3.110.0060.00314.09
7.3.100.0030.00813.90
7.3.90.0030.00614.03
7.3.80.0050.00713.92
7.3.70.0050.00514.12
7.3.60.0030.00614.17
7.3.50.0060.00314.04
7.3.40.0030.00713.99
7.3.30.0050.00514.01
7.3.20.0050.00615.94
7.3.10.0050.00715.92
7.3.00.0060.00515.87
7.2.340.0080.00413.32
7.2.330.0130.00013.35
7.2.320.0100.00313.34
7.2.310.0090.00413.40
7.2.300.0130.00013.17
7.2.290.0100.00313.21
7.2.280.0100.00313.32
7.2.270.0120.00013.29
7.2.260.0090.00313.39
7.2.250.0050.01213.96
7.2.240.0070.01114.10
7.2.230.0080.00714.18
7.2.220.0100.00514.12
7.2.210.0080.00614.21
7.2.200.0090.00614.21
7.2.190.0080.00514.19
7.2.180.0090.00514.18
7.2.170.0070.00414.20
7.2.160.0020.01214.07
7.2.150.0080.00315.89
7.2.140.0060.00915.87
7.2.130.0070.00616.05
7.2.120.0050.00615.99
7.2.110.0050.00716.06
7.2.100.0090.00615.98
7.2.90.0090.00415.75
7.2.80.0070.00416.01
7.2.70.0090.00416.06
7.2.60.0090.00516.20
7.2.50.0070.00916.09
7.2.40.0110.00315.96
7.2.30.0030.01115.97
7.2.20.0110.00515.83
7.2.10.0090.00516.00
7.2.00.0070.00717.12
7.1.330.0100.00515.01
7.1.320.0090.00514.83
7.1.310.0050.00615.07
7.1.300.0070.00514.87
7.1.290.0050.00914.99
7.1.280.0060.00514.95
7.1.270.0050.00814.97
7.1.260.0100.00515.03
7.1.250.0090.00314.94
7.1.240.0110.00214.92
7.1.230.0060.00715.05
7.1.220.0060.00715.04
7.1.210.0100.00314.85
7.1.200.0070.00715.09
7.1.190.0100.00414.94
7.1.180.0100.00514.86
7.1.170.0080.00314.91
7.1.160.0050.00615.03
7.1.150.0070.00814.83
7.1.140.0060.00515.00
7.1.130.0040.01014.94
7.1.120.0050.00914.84
7.1.110.0070.00714.95
7.1.100.0060.00515.90
7.1.90.0080.00714.85
7.1.80.0060.00714.89
7.1.70.0100.00415.54
7.1.60.0060.01016.52
7.1.50.0110.00515.52
7.1.40.0110.00314.89
7.1.30.0030.01114.85
7.1.20.0060.00514.89
7.1.10.0100.00514.76
7.1.00.0060.02917.33
7.0.330.0090.00314.59
7.0.320.0060.00714.68
7.0.310.0070.00514.57
7.0.300.0060.00614.76
7.0.290.0050.00914.50
7.0.280.0080.00714.55
7.0.270.0100.00214.70
7.0.260.0060.00714.61
7.0.250.0070.00714.87
7.0.240.0090.00114.59
7.0.230.0080.00614.60
7.0.220.0090.00314.67
7.0.210.0090.00414.69
7.0.200.0090.00215.20
7.0.190.0080.00514.60
7.0.180.0090.00414.69
7.0.170.0070.00614.77
7.0.160.0070.00414.47
7.0.150.0100.00514.59
7.0.140.0100.00514.66
7.0.130.0070.00414.68
7.0.120.0080.00614.62
7.0.110.0060.00714.70
7.0.100.0180.03116.40
7.0.90.0220.02516.29
7.0.80.0090.02316.40
7.0.70.0260.03416.47
7.0.60.0090.03016.38
7.0.50.0270.02416.53
7.0.40.0110.02615.81
7.0.30.0110.01515.91
7.0.20.0120.02915.67
7.0.10.0050.02015.78
7.0.00.0070.02115.86
5.6.400.0090.00513.54
5.6.390.0060.00613.40
5.6.380.0080.00613.45
5.6.370.0030.01113.37
5.6.360.0100.00113.22
5.6.350.0090.00413.19
5.6.340.0090.00613.64
5.6.330.0070.00613.43
5.6.320.0070.00613.21
5.6.310.0060.00813.32
5.6.300.0080.00613.35
5.6.290.0090.00513.42
5.6.280.0050.03015.93
5.6.270.0030.00713.26
5.6.260.0040.00713.48
5.6.250.0050.03115.84
5.6.240.0090.01815.84
5.6.230.0030.03415.69
5.6.220.0090.02815.80
5.6.210.0060.02815.74
5.6.200.0070.03415.99
5.6.190.0070.03115.89
5.6.180.0050.03416.06
5.6.170.0070.02916.05
5.6.160.0100.03415.99
5.6.150.0100.02915.91
5.6.140.0080.02915.87
5.6.130.0060.02815.86
5.6.120.0090.01915.98
5.6.110.0070.02815.92
5.6.100.0050.02315.82
5.6.90.0100.01715.85
5.6.80.0130.02115.65
5.6.70.0050.02015.85
5.6.60.0070.02115.65
5.6.50.0060.03015.71
5.6.40.0080.02115.69
5.6.30.0050.02915.76
5.6.20.0050.03115.69
5.6.10.0070.03115.79
5.6.00.0040.03115.64
5.5.380.0050.03215.74
5.5.370.0050.03515.62
5.5.360.0090.02915.64
5.5.350.0050.03115.69
5.5.340.0120.02515.74
5.5.330.0050.03215.76
5.5.320.0100.02015.83
5.5.310.0080.01615.82
5.5.300.0060.02115.74
5.5.290.0060.02515.80
5.5.280.0070.02715.80
5.5.270.0070.01815.74
5.5.260.0090.01615.82
5.5.250.0070.02415.73
5.5.240.0050.02915.69
5.5.230.0090.02515.43
5.5.220.0060.02415.70
5.5.210.0060.02915.65
5.5.200.0090.02615.60
5.5.190.0080.01715.62
5.5.180.0110.02315.53
5.5.170.0070.00513.06
5.5.160.0030.03115.49
5.5.150.0080.02715.58
5.5.140.0070.01715.57
5.5.130.0060.01715.38
5.5.120.0120.03015.41
5.5.110.0040.03215.44
5.5.100.0080.02815.50
5.5.90.0070.02215.53
5.5.80.0090.02315.44
5.5.70.0060.02515.41
5.5.60.0070.01715.51
5.5.50.0060.02915.59
5.5.40.0120.02615.50
5.5.30.0100.03115.46
5.5.20.0080.02915.44
5.5.10.0070.02815.46
5.5.00.0080.02915.48
5.4.450.0070.02516.02
5.4.440.0100.03215.97
5.4.430.0070.02215.88
5.4.420.0080.03615.97
5.4.410.0070.02315.82
5.4.400.0070.02915.65
5.4.390.0110.02215.80
5.4.380.0080.03215.66
5.4.370.0060.03915.75
5.4.360.0070.02415.84
5.4.350.0120.03515.63
5.4.340.0060.02315.86
5.4.330.0080.00412.59
5.4.320.0070.04215.81
5.4.310.0070.02515.77
5.4.300.0110.03615.87
5.4.290.0090.02815.86
5.4.280.0060.03515.85
5.4.270.0080.03015.76
5.4.260.0050.02315.79
5.4.250.0070.03015.77
5.4.240.0110.03815.66
5.4.230.0070.03515.63
5.4.220.0100.03115.59
5.4.210.0050.03515.62
5.4.200.0060.02815.76
5.4.190.0070.03115.75
5.4.180.0070.04015.70
5.4.170.0070.03015.64
5.4.160.0080.04015.61
5.4.150.0100.03615.72
5.4.140.0100.03314.46
5.4.130.0080.03314.38
5.4.120.0130.03014.44
5.4.110.0080.02014.52
5.4.100.0070.04014.43
5.4.90.0050.04014.35
5.4.80.0030.02514.57
5.4.70.0100.03314.36
5.4.60.0060.02014.47
5.4.50.0100.02814.31
5.4.40.0100.03214.36
5.4.30.0070.01814.38
5.4.20.0110.02614.34
5.4.10.0070.01714.39
5.4.00.0070.01514.04
5.3.290.0080.03213.99
5.3.280.0070.04013.90
5.3.270.0100.03613.96
5.3.260.0090.03713.97
5.3.250.0080.03713.97
5.3.240.0120.02013.79
5.3.230.0080.04113.82
5.3.220.0100.03713.81
5.3.210.0070.03713.96
5.3.200.0020.04413.83
5.3.190.0060.02413.95
5.3.180.0070.03714.03
5.3.170.0060.02414.00
5.3.160.0060.03513.89
5.3.150.0070.03713.91
5.3.140.0040.02513.96
5.3.130.0060.04113.85
5.3.120.0080.02213.86
5.3.110.0100.03013.96
5.3.100.0050.02814.00
5.3.90.0080.04014.03
5.3.80.0050.02013.96
5.3.70.0080.03213.88
5.3.60.0060.02013.86
5.3.50.0050.02013.91
5.3.40.0070.03813.92
5.3.30.0090.03813.93
5.3.20.0080.02413.90
5.3.10.0070.03313.85
5.3.00.0070.03513.71
5.2.170.0040.03213.45
5.2.160.0110.02013.45
5.2.150.0040.02313.45
5.2.140.0060.02913.28
5.2.130.0030.02313.36
5.2.120.0060.02613.31
5.2.110.0030.03413.31
5.2.100.0020.03613.36
5.2.90.0100.02813.38
5.2.80.0080.03213.38
5.2.70.0050.02513.45
5.2.60.0020.02513.35
5.2.50.0050.01913.33
5.2.40.0050.01613.32
5.2.30.0020.01713.27
5.2.20.0060.01713.21
5.2.10.0050.01613.33
5.2.00.0040.03413.27
5.1.60.0050.02412.86
5.1.50.0030.01913.00
5.1.40.0030.02112.87
5.1.30.0060.01613.12
5.1.20.0060.01712.92
5.1.10.0030.01612.84
5.1.00.0050.01912.76
5.0.50.0070.01912.72
5.0.40.0040.02412.72
5.0.30.0000.03112.72
5.0.20.0000.02212.72
5.0.10.0020.02212.72
5.0.00.0030.02012.72
4.4.90.0030.01812.72
4.4.80.0030.00812.72
4.4.70.0020.01312.72
4.4.60.0030.00812.72
4.4.50.0000.01512.72
4.4.40.0020.02812.72
4.4.30.0070.00812.72
4.4.20.0040.00812.72
4.4.10.0020.02212.72
4.4.00.0040.02812.72
4.3.110.0050.01312.72
4.3.100.0050.00512.72
4.3.90.0020.01012.72
4.3.80.0020.01712.72
4.3.70.0050.01312.72
4.3.60.0020.00812.72
4.3.50.0000.01012.72
4.3.40.0020.02212.72
4.3.30.0020.01712.72
4.3.20.0010.01712.72
4.3.10.0000.01012.72
4.3.00.0010.01512.72

preferences:
26.43 ms | 401 KiB | 5 Q