3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * File to handle all API requests * Accepts GET and POST * * Each request will be identified by TAG * Response will be JSON data /** * check for POST request */ if (isset($_POST['tag']) && $_POST['tag'] != '') { // get tag $tag = $_POST['tag']; // include db handler require_once 'include/DB_Functions.php'; $db = new DB_Functions(); // response Array $response = array("tag" => $tag, "error" => FALSE); // check for tag type if ($tag == 'login') { // Request type is check Login $email = $_POST['email']; $password = $_POST['password']; // check for user $user = $db->getUserByEmailAndPassword($email, $password); if ($user != false) { // user found $response["error"] = FALSE; $response["user"]["unique_id"] = $user["unique_id"]; $response["user"]["name"] = $user["name"]; $response["user"]["email"] = $user["email"]; $response["user"]["created_at"] = $user["created_at"]; $response["user"]["updated_at"] = $user["updated_at"]; $response["user"]["StudentID"] = $user["StudentID"]; echo json_encode($response); } else { // user not found // echo json with error = 1 $response["error"] = TRUE; $response["error_msg"] = "Incorrect email or password!"; echo json_encode($response); } } else if ($tag == 'register') { // Request type is Register new user $name = $_POST['name']; $email = $_POST['email']; $password = $_POST['password']; // check if user is already existed if ($db->isUserExisted($email)) { // user is already existed - error response $response["error"] = TRUE; $response["error_msg"] = "User already existed"; echo json_encode($response); } else { // store user $user = $db->storeUser($name, $email, $password); if ($user) { // user stored successfully $response["error"] = FALSE; $response["uid"] = $user["unique_id"]; $response["user"]["name"] = $user["name"]; $response["user"]["email"] = $user["email"]; $response["user"]["created_at"] = $user["created_at"]; $response["user"]["updated_at"] = $user["updated_at"]; echo json_encode($response); } else { // user failed to store $response["error"] = TRUE; $response["error_msg"] = "Error occurred in registration"; echo json_encode($response); } } } else if ($tag == 'getCourses') { $user = FALSE; if(isset ($_POST['StudentID'])) $user = $_POST['StudentID']; $selectionKey = $_POST['searchKey']; $selectionValue = $_POST['searchValue']; $response = $db->getCourses($user, $selectionKey, $selectionValue); if($response){ $response["error"] = FALSE; } else { $response["error"]=TRUE; $response["error_mesg"] = "Error occurred getting the courses"; } echo json_encode($response); } else if ($tag = 'addCourse'){ // Request type is add a course to a specific student $StudentID = $_POST['StudentID']; $CourseID = $_POST['CourseID']; $email = $_POST['email']; // check if user is already existed if ($db->isUserExisted($email)) { // store course $course = $db->storeCourse($StudentID, $CourseID); if ($course !=FALSE) { // course stored successfully $response["error"] = FALSE; $response["course"]["StudentID"] = $course["StudentID"]; $response["course"]["CourseID"] = $course["CourseID"]; echo json_encode($response); } else { // course failed to store $response["error"] = TRUE; $response["error_msg"] = "Error occured adding courses"; echo json_encode($response); } } else{ $response["error"] = TRUE; $response["error_msg"] = "User does not exist"; echo json_encode($response); } } else if($tag == 'getFriends'){ $courseID = $_POST['courseID']; $studentID = $_POST['studentID']; $result = $db->getFriendsByCourseIdAndStudentId($courseID, $studentID); if($result !=FALSE){ $result['error']=FALSE; } else{ $result['error']=TRUE; $result["error_mesg"] = "Error occurred retrieving friends"; } echo json_encode($result); } else { // user failed to store $response["error"] = TRUE; $response["error_msg"] = "Unknow 'tag' value. It should be either 'login' or 'register'"; echo json_encode($response); } } else { $response["error"] = TRUE; $response["error_msg"] = "Required parameter 'tag' is missing!"; echo json_encode($response); } ?>

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.0150.00016.88
8.3.50.0130.00721.07
8.3.40.0080.00818.84
8.3.30.0090.00618.71
8.3.20.0040.00420.20
8.3.10.0000.00823.36
8.3.00.0000.00819.78
8.2.180.0040.01118.54
8.2.170.0110.00422.96
8.2.160.0100.00319.55
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0070.00026.16
8.2.120.0070.00317.84
8.2.110.0050.00522.13
8.2.100.0090.00317.84
8.2.90.0000.00819.24
8.2.80.0040.00417.97
8.2.70.0030.00617.88
8.2.60.0000.00818.05
8.2.50.0040.00418.07
8.2.40.0040.00421.01
8.2.30.0040.00420.70
8.2.20.0040.00417.91
8.2.10.0000.00718.13
8.2.00.0000.00718.21
8.1.280.0040.01225.92
8.1.270.0110.00423.84
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0060.00320.99
8.1.230.0040.00820.97
8.1.220.0040.00417.88
8.1.210.0000.00818.77
8.1.200.0060.00317.47
8.1.190.0040.00417.35
8.1.180.0040.00418.10
8.1.170.0060.00320.44
8.1.160.0040.00422.10
8.1.150.0040.00418.85
8.1.140.0030.00621.34
8.1.130.0020.00519.17
8.1.120.0000.00717.51
8.1.110.0000.00717.39
8.1.100.0020.00517.48
8.1.90.0020.00517.54
8.1.80.0030.00617.47
8.1.70.0000.00817.47
8.1.60.0040.00417.65
8.1.50.0040.00417.53
8.1.40.0000.01017.58
8.1.30.0030.00517.59
8.1.20.0040.00417.71
8.1.10.0040.00417.54
8.1.00.0040.00417.54
8.0.300.0000.00718.77
8.0.290.0030.00916.58
8.0.280.0000.00718.39
8.0.270.0030.00317.29
8.0.260.0080.00016.78
8.0.250.0050.00316.96
8.0.240.0000.00716.86
8.0.230.0040.00416.99
8.0.220.0000.00816.84
8.0.210.0050.00316.94
8.0.200.0030.00316.99
8.0.190.0000.00816.89
8.0.180.0040.00716.85
8.0.170.0000.00816.95
8.0.160.0040.00416.82
8.0.150.0000.00816.90
8.0.140.0070.00016.91
8.0.130.0030.00613.32
8.0.120.0070.00016.92
8.0.110.0070.00016.75
8.0.100.0070.00016.92
8.0.90.0040.00416.93
8.0.80.0080.00816.88
8.0.70.0000.00816.91
8.0.60.0040.00416.88
8.0.50.0070.00016.84
8.0.30.0110.00517.22
8.0.20.0140.00717.40
8.0.10.0040.00417.00
8.0.00.0140.00716.83
7.4.330.0050.00015.15
7.4.320.0060.00016.70
7.4.300.0070.00016.74
7.4.290.0000.00716.70
7.4.280.0000.01116.64
7.4.270.0030.00316.71
7.4.260.0030.00316.59
7.4.250.0040.00416.57
7.4.240.0000.00716.77
7.4.230.0070.00016.63
7.4.220.0130.00616.64
7.4.210.0060.01016.56
7.4.200.0030.00316.73
7.4.160.0120.00616.51
7.4.150.0110.00717.40
7.4.140.0100.01317.86
7.4.130.0070.01116.61
7.4.120.0060.01216.67
7.4.110.0090.00916.49
7.4.100.0170.00716.61
7.4.90.0150.00316.64
7.4.80.0140.01019.39
7.4.70.0070.01116.71
7.4.60.0100.00716.69
7.4.50.0050.00316.43
7.4.40.0140.00416.77
7.4.30.0070.01016.73
7.4.00.0050.01314.73
7.3.330.0050.00013.31
7.3.320.0000.00513.12
7.3.310.0040.00416.35
7.3.300.0030.00316.38
7.3.290.0070.01116.32
7.3.280.0110.01016.39
7.3.270.0130.00317.40
7.3.260.0040.01416.34
7.3.250.0120.00516.34
7.3.240.0120.00716.57
7.3.230.0040.01116.47
7.3.210.0070.01016.59
7.3.200.0060.01016.54
7.3.190.0060.01016.70
7.3.180.0060.00916.45
7.3.170.0090.00916.67
7.3.160.0100.01016.68
7.3.120.0070.01115.07
7.3.110.0060.01214.75
7.3.100.0110.00414.95
7.3.90.0030.01014.71
7.3.80.0070.01114.94
7.3.70.0040.01214.75
7.3.60.0060.00914.72
7.3.50.0040.00814.72
7.3.40.0030.01015.02
7.3.30.0030.01214.79
7.3.20.0060.00916.73
7.3.10.0000.01116.72
7.3.00.0060.00816.41
7.2.330.0120.00616.54
7.2.320.0120.00616.64
7.2.310.0030.01716.91
7.2.300.0030.01316.55
7.2.290.0060.01016.73
7.2.250.0100.01015.00
7.2.240.0030.01715.22
7.2.230.0090.00915.30
7.2.220.0040.00814.88
7.2.210.0030.01015.26
7.2.200.0000.01115.13
7.2.190.0070.00715.21
7.2.180.0070.00715.06
7.2.170.0100.00715.21
7.2.60.0130.00016.80
7.1.330.0070.00715.84
7.1.320.0120.00315.73
7.1.310.0120.00315.75
7.1.300.0070.00415.45
7.1.290.0000.01515.62
7.1.280.0080.00815.46
7.1.270.0080.00315.48
7.1.260.0000.01215.71
7.1.200.0000.01215.82
7.1.70.0000.01417.27
7.1.60.0070.01419.50
7.1.50.0040.01816.57
7.1.00.0070.07322.26
7.0.200.0040.00715.12
7.0.90.1030.06720.10
7.0.80.0600.08020.06
7.0.70.0500.03720.00
7.0.60.0600.07720.05
7.0.50.0630.07720.44
7.0.40.0100.08020.11
7.0.30.0230.07319.95
7.0.20.0170.07720.08
7.0.10.0030.05020.10
7.0.00.0200.07720.09
5.6.280.0030.03021.07
5.6.240.0100.08720.64
5.6.230.0070.05020.67
5.6.220.0070.04720.53
5.6.210.0100.08320.63
5.6.200.0130.07021.13
5.6.190.0070.05021.00
5.6.180.0100.05721.10
5.6.170.0070.05721.21
5.6.160.0170.07321.13
5.6.150.0130.07721.08
5.6.140.0100.07720.99
5.6.130.0100.04021.04
5.6.120.0030.04720.99
5.6.110.0070.08321.09
5.6.100.0000.09021.11
5.6.90.0070.09021.16
5.6.80.0130.07020.56
5.6.70.0130.07020.49
5.6.60.0070.08020.35
5.6.50.0100.07020.51
5.6.40.0100.05720.36
5.6.30.0030.04320.44
5.6.20.0000.06720.49
5.6.10.0100.06320.44
5.6.00.0170.07020.38
5.5.380.0030.08720.41
5.5.370.0030.09320.40
5.5.360.0070.08320.58
5.5.350.0030.05720.49
5.5.340.0100.04020.85
5.5.330.0030.06020.91
5.5.320.0070.06720.92
5.5.310.0130.07720.91
5.5.300.0200.04720.95
5.5.290.0030.05320.94
5.5.280.0030.07020.87
5.5.270.0070.08320.89
5.5.260.0070.08720.84
5.5.250.0170.05020.73
5.5.240.0030.07020.31
5.5.230.0100.06020.29
5.5.220.0070.08720.17
5.5.210.0070.04720.19
5.5.200.0070.08020.26
5.5.190.0130.07020.28
5.5.180.0100.07720.19
5.5.160.0130.05020.30
5.5.150.0100.07720.14
5.5.140.0070.07720.26
5.5.130.0070.08020.30
5.5.120.0070.05020.30
5.5.110.0130.05020.13
5.5.100.0100.08720.09
5.5.90.0170.06720.02
5.5.80.0030.07020.15
5.5.70.0100.07320.18
5.5.60.0130.06019.97
5.5.50.0070.08320.01
5.5.40.0100.08020.12
5.5.30.0030.05320.12
5.5.20.0170.06720.18
5.5.10.0030.08320.13
5.5.00.0030.08320.00
5.4.450.0130.07019.46
5.4.440.0030.05719.29
5.4.430.0100.07319.35
5.4.420.0030.06319.38
5.4.410.0200.05319.11
5.4.400.0100.06719.13
5.4.390.0070.04319.13
5.4.380.0030.07318.79
5.4.370.0000.06319.14
5.4.360.0030.08019.09
5.4.350.0030.04718.78
5.4.340.0070.08718.79
5.4.320.0070.04318.96
5.4.310.0070.05718.79
5.4.300.0130.06019.11
5.4.290.0100.07319.04
5.4.280.0100.03318.81
5.4.270.0000.05319.05
5.4.260.0100.08019.02
5.4.250.0100.06019.23
5.4.240.0030.04319.07
5.4.230.0030.05319.14
5.4.220.0000.08718.89
5.4.210.0070.05319.04
5.4.200.0100.08019.22
5.4.190.0030.05319.09
5.4.180.0070.06319.04
5.4.170.0130.07018.89
5.4.160.0100.07319.03
5.4.150.0070.07018.96
5.4.140.0030.05016.40
5.4.130.0000.07316.30
5.4.120.0070.07316.37
5.4.110.0100.07716.38
5.4.100.0130.07016.36
5.4.90.0200.06316.36
5.4.80.0070.07316.38
5.4.70.0030.08016.38
5.4.60.0130.06316.27
5.4.50.0100.07016.48
5.4.40.0070.07316.46
5.4.30.0330.04716.43
5.4.20.0000.07716.23
5.4.10.0070.07316.28
5.4.00.0130.06315.84

preferences:
32.89 ms | 401 KiB | 5 Q