3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * Instagram's proxy API * reads Instagram pages and gets embedded data, * then returns it as json or jsonp. * By Francisco Diaz :: picssel.com * Revision March 2015 */ /*$sawOrigin = false; $originHeader = $_SERVER['HTTP_ORIGIN']; $originHeader = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : null; if ($originHeader) { echo "Origin header value: $originHeader"; }*/ /***** get request origin and set domain restrictions *****/ $HTTP_ORIGIN = $_SERVER['HTTP_ORIGIN']; // 1). ALL domains // header("Access-Control-Allow-Origin: *"); // 2). Single domain /* if ($HTTP_ORIGIN == "http://www.picssel.com"){ header("Access-Control-Allow-Origin: $HTTP_ORIGIN"); } */ // 3). Several domains, e.g. http://picssel.com, http://fiddle.jshell.net, etc. $domains_allowed = array("http://www.picssel.com", "http://www.picssel.ca"); if(in_array( $HTTP_ORIGIN, $domains_allowed )){ header("Access-Control-Allow-Origin: $HTTP_ORIGIN"); } /***** functions *****/ // sanitize input function sanitize_input($input){ $input = trim($input); $input = stripslashes($input); $input = strip_tags($input); $input = htmlspecialchars($input); return $input; }; // process data function process_data($dataFile, $requestType){ $data_length = strlen($dataFile); if( $data_length > 0 ){ $start_position = strpos( $dataFile ,'{"static_root"' ); // start position $trimmed_before = trim( substr($dataFile, $start_position) ); // trim preceding content $end_position = strpos( $trimmed_before, '</script>'); // end position $trimmed = trim( substr( $trimmed_before, 0, $end_position) ); // trim content $jsondata = substr( $trimmed, 0, -1); // remove extra trailing ";" header("HTTP/1.0 200 OK"); // JSONP response if(array_key_exists('callback', $_GET)){ header('Content-Type: text/javascript; charset=utf8'); $callback = $_GET['callback']; return $callback."(".$jsondata.");"; } // JSON response else { header('Content-Type: application/json; charset=utf-8'); return $jsondata; } } else { // invalid username or media header("HTTP/1.0 400 BAD REQUEST"); header('Content-Type: text/html; charset=utf-8'); die("invalid $requestType"); } }; /***** Get user's input *****/ $user = sanitize_input( $_GET['user'] ); // expects something like "instagram" (username) $media = sanitize_input( $_GET['media'] ); // expects something like "mOFsFhAp4f" (shortcode) /***** set context *****/ $context = stream_context_create(array( 'http' => array( 'timeout' => 10 // in seconds ) ) ); /***** validate request type and return response *****/ // user, including last 20 media posts if( !empty($user) && empty($media) ){ $requestType = "user"; $dataFile = @ file_get_contents("http://instagram.com/".$user, NULL, $context); echo process_data($dataFile, $requestType); } // media elseif( empty($user) && !empty($media) ){ $requestType = "media"; $dataFile = @ file_get_contents("http://instagram.com/p/".$media, NULL, $context); echo process_data($dataFile, $requestType); } // invalid : two or more parameters were passed elseif( !empty($user) && !empty($media) ){ header("HTTP/1.0 400 BAD REQUEST"); header('Content-Type: text/html; charset=utf-8'); die("only one parameter allowed"); } // invalid : none or invalid parameters were passed elseif( empty($user) && empty($media) ){ header("HTTP/1.0 400 BAD REQUEST"); header('Content-Type: text/html; charset=utf-8'); die("invalid parameters"); }; ?>

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.3.60.0110.00418.40
8.3.50.0130.00618.20
8.3.40.0120.00318.72
8.3.30.0060.00918.85
8.3.20.0080.00020.37
8.3.10.0040.00423.71
8.3.00.0050.00319.26
8.2.180.0150.00418.29
8.2.170.0100.00622.96
8.2.160.0110.00419.45
8.2.150.0080.00024.18
8.2.140.0050.00324.66
8.2.130.0050.00321.11
8.2.120.0040.00426.35
8.2.110.0050.00522.26
8.2.100.0070.00417.91
8.2.90.0040.00420.60
8.2.80.0030.00517.97
8.2.70.0000.00918.05
8.2.60.0000.00818.12
8.2.50.0030.00518.21
8.2.40.0040.00420.44
8.2.30.0070.00019.55
8.2.20.0070.00018.13
8.2.10.0000.00918.12
8.2.00.0000.00818.22
8.1.280.0090.00625.92
8.1.270.0080.00020.22
8.1.260.0050.00326.35
8.1.250.0000.00728.09
8.1.240.0070.00320.50
8.1.230.0100.00317.42
8.1.220.0060.00317.74
8.1.210.0050.00318.84
8.1.200.0030.00517.48
8.1.190.0070.00317.35
8.1.180.0030.00618.10
8.1.170.0080.00018.65
8.1.160.0070.00018.79
8.1.150.0000.00820.30
8.1.140.0030.00517.75
8.1.130.0030.00318.82
8.1.120.0000.00717.39
8.1.110.0090.00017.51
8.1.100.0040.00417.49
8.1.90.0040.00417.57
8.1.80.0000.00817.49
8.1.70.0070.00017.40
8.1.60.0050.00217.64
8.1.50.0000.00917.38
8.1.40.0060.00317.54
8.1.30.0040.00817.57
8.1.20.0020.00517.66
8.1.10.0040.00417.51
8.1.00.0030.01017.54
8.0.300.0040.00420.03
8.0.290.0030.00616.75
8.0.280.0000.00818.48
8.0.270.0070.00017.16
8.0.260.0040.00416.91
8.0.250.0050.00317.04
8.0.240.0070.00017.02
8.0.230.0030.00517.05
8.0.220.0000.00716.92
8.0.210.0070.00017.02
8.0.200.0000.00717.05
8.0.190.0020.00516.92
8.0.180.0000.00717.01
8.0.170.0040.00416.96
8.0.160.0030.00517.11
8.0.150.0030.00516.88
8.0.140.0040.00416.93
8.0.130.0060.00013.32
8.0.120.0040.00416.94
8.0.110.0000.00716.81
8.0.100.0040.00416.85
8.0.90.0040.00416.86
8.0.80.0040.01217.03
8.0.70.0080.00016.84
8.0.60.0000.00716.82
8.0.50.0000.00816.78
8.0.30.0120.00917.02
8.0.20.0110.01117.41
8.0.10.0000.00717.09
8.0.00.0080.00916.93
7.4.330.0050.00015.55
7.4.320.0040.00416.46
7.4.300.0000.00616.54
7.4.290.0000.00716.50
7.4.280.0070.00016.55
7.4.270.0040.00416.53
7.4.260.0040.00416.38
7.4.250.0080.00016.48
7.4.240.0000.00716.49
7.4.230.0000.00716.65
7.4.220.0040.00416.64
7.4.210.0060.00916.46
7.4.200.0000.00716.62
7.4.160.0080.01016.48
7.4.150.0140.00517.40
7.4.140.0130.00617.86
7.4.130.0120.00616.61
7.4.120.0160.00416.62
7.4.00.0070.00316.40
7.3.330.0000.00813.23
7.3.320.0000.00613.26
7.3.310.0070.00016.30
7.3.300.0040.00416.35
7.3.290.0060.01016.36
7.3.280.0070.00716.41
7.3.270.0090.00917.40
7.3.260.0090.01016.46
7.3.250.0110.00716.48
7.3.240.0100.01316.45
7.2.10.0170.00517.93
5.4.00.0030.00313.11

preferences:
61.96 ms | 401 KiB | 5 Q