3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Priatek Vending PHP Server-Side * Checks POST requests. It checks a 'tag' in a post response, and looks * for other tag-specific data. Tag if one of the following, along with the * other required data: * * Tag Other Tag 1 Other Tag 2 * ========================================== * login | ID OR user_name | password * logout | ID OR user_name | * getTickets | user_name | * addTickets | user_name | tickets * subTickets | user_name | tickets * * Other Tag Descriptions * ========================================== * user_name : ther user's name on the databae in the user_name column * ID : the user's ID in the ID column * password : the contents of the pass_hash column * ticket : an integer of the number of tickets to add or remove * * Brief Explinations * ========================================== * login - User to lookup and mark a user a logged in * logout - Logout a user setting a boolean "loggedin" in the databse. * getTickets - Return a user's tickets * addTickets - Add to a user's tickets * subTickets - Subtract from a user's tickets * viewLogs - Return the first ten entires in the adminlogs and redemptionstable */ //Echos an error message, given a tag, back to the user function sendError($tag, $message) { $response = array("tag" => $tag, "error" => TRUE); $response['error_msg'] = $message; echo json_encode($response); } if (isset($_POST['tag']) && $_POST['tag'] != '') { require_once 'include/DB_Functions.php'; $db = new DB_Functions(); //object of the class containing all the functions //response Array. Will be json_encode'd sent back $tag = $_POST['tag']; $response = array("tag" => $tag, "error" => FALSE); /********response when tag == login*************/ if ($tag == 'login') { // Request type is check Login $id = $_POST['ID']; $username = $_POST['user_name']; $password = $_POST['password']; $machinesID = $_POST["machinesID"]; $itemsID = $_POST["itemsID"]; // Lookup by either username, or ID $user = $db->loginUserByPassword($id, $username, $password, $machinesID); if ($user != false) { //Record was found $response["user"]["tickets"] = $user["tickets"]; $response["error"] = FALSE; $response["user"]["name"] = $user["name"]; $response["user"]["id"] = $user["ID"]; $response["user"]["created_at"] = $user["created_at"]; $response["user"]["updated_at"] = $user["updated_at"]; echo json_encode($response); } else { //record was not found sendError($tag, "Incorrect id or password!"); } } /********response when tag == ViewLogs*************/ else if ($tag == 'viewLogs') { $id = $_POST["id"]; $logs = $db->getMachineLogs($id); if($logs != FALSE) { $response["logs"] = $logs; echo json_encode($response); } else { sendError($tag, "Error retrieving logs"); } } /********response when tag == addTickets*************/ else if ($tag == 'addTickets') { //TODO: add a restrain, if the user doesnt exist tickets cannot be adde $user_name = $_POST["user_name"]; $tickets = $_POST["tickets"]; $currentBalance = $db->getTickets($user_name); $newBalance = $currentBalance["tickets"] + $tickets; if($db->addTickets($user_name, $tickets)){ $response["newBalance"]= $newBalance; echo json_encode($response); } else { sendError($tag, "processing error"); } } /********response when tag == subTickets*************/ else if ($tag == 'subTickets'){ //TODO: add a restrain, if the user doesnt exist tickets cannot be subtracted $user_name = $_POST["user_name"]; $tickets = $_POST["tickets"]; $machinesID = $_POST["machinesID"]; $itemsID = $_POST["itemsID"]; $currentBalance = $db->getTickets($user_name, $machinesID, $itemsID); $newBalance = $currentBalance["tickets"] - $tickets; if($newBalance > 0) { if($db->subTickets($user_name, $tickets)) { $response["newBalance"]= $newBalance; echo json_encode($response); } else { sendError($tag, "processing error"); } } else { sendError($tag, "Subtracting tickets will result in a negative value!"); } } /******** response when tag == getTickets *************/ else if ($tag == 'getTickets') { $user_name = $_POST["user_name"]; $balance = $db->getTickets($user_name); if($balance != FALSE) { $response["tickets"] = $balance["tickets"]; echo json_encode($response); } else { sendError($tag, "error processing the tickets"); } } /********response when tag == unknown*************/ else { sendError($tag, "Unknown tag given"); } /********response when tag == empty*************/ } else { sendError($tag, "Empty tag value given"); } ?>

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.40.0120.00318.88
8.3.30.0100.01018.97
8.3.20.0040.00420.43
8.3.10.0040.00423.62
8.3.00.0000.00818.05
8.2.170.0150.00022.96
8.2.160.0150.00420.47
8.2.150.0040.00424.18
8.2.140.0000.00824.66
8.2.130.0060.00326.16
8.2.120.0060.00317.75
8.2.110.0030.00722.11
8.2.100.0090.00318.29
8.2.90.0030.00519.30
8.2.80.0060.00317.97
8.2.70.0000.00917.88
8.2.60.0000.00818.05
8.2.50.0090.00318.09
8.2.40.0040.00420.55
8.2.30.0020.00519.66
8.2.20.0000.00817.78
8.2.10.0000.00818.14
8.2.00.0050.00218.12
8.1.270.0090.00923.96
8.1.260.0000.00826.35
8.1.250.0070.00028.09
8.1.240.0050.00520.95
8.1.230.0080.00417.95
8.1.220.0090.00017.91
8.1.210.0030.00518.77
8.1.200.0100.00017.48
8.1.190.0050.00317.48
8.1.180.0040.00418.10
8.1.170.0090.00018.60
8.1.160.0030.00620.87
8.1.150.0040.00419.02
8.1.140.0060.00321.30
8.1.130.0030.00317.80
8.1.120.0000.00717.48
8.1.110.0050.00317.45
8.1.100.0000.00717.54
8.1.90.0070.00017.45
8.1.80.0040.00417.44
8.1.70.0070.00017.46
8.1.60.0040.00417.68
8.1.50.0000.00917.57
8.1.40.0040.00417.49
8.1.30.0060.00317.64
8.1.20.0030.00617.58
8.1.10.0040.00417.71
8.1.00.0050.00317.46
8.0.300.0060.00318.77
8.0.290.0000.00716.88
8.0.280.0000.00818.52
8.0.270.0000.00717.35
8.0.260.0030.00317.26
8.0.250.0070.00017.15
8.0.240.0040.00416.97
8.0.230.0050.00216.99
8.0.220.0000.00716.89
8.0.210.0020.00516.92
8.0.200.0000.00717.00
8.0.190.0030.00617.09
8.0.180.0070.00016.98
8.0.170.0080.00017.01
8.0.160.0050.00317.04
8.0.150.0000.00817.01
8.0.140.0000.00717.02
8.0.130.0050.00213.44
8.0.120.0040.00417.05
8.0.110.0080.00017.06
8.0.100.0050.00317.10
8.0.90.0020.00517.01
8.0.80.0040.01117.01
8.0.70.0070.00016.95
8.0.60.0040.00417.00
8.0.50.0020.00516.94
8.0.30.0120.00717.22
8.0.20.0090.00917.41
8.0.10.0040.00417.06
8.0.00.0090.00816.99
7.4.330.0030.00215.08
7.4.320.0030.00316.63
7.4.300.0000.00616.61
7.4.290.0000.00716.64
7.4.280.0000.00716.55
7.4.270.0070.00016.69
7.4.260.0000.00716.59
7.4.250.0040.00416.47
7.4.240.0020.00616.50
7.4.230.0070.00016.72
7.4.220.0120.00916.62
7.4.210.0060.01216.55
7.4.200.0000.00816.70
7.4.160.0000.01516.55
7.4.150.0060.01117.40
7.4.140.0120.00917.86
7.4.130.0060.01316.65
7.4.120.0110.00816.57
7.4.110.0180.00416.71
7.4.100.0120.00916.75
7.4.90.0030.01416.56
7.4.80.0070.01019.39
7.4.70.0060.01116.59
7.4.60.0120.01116.71
7.4.50.0000.00816.51
7.4.40.0080.00916.45
7.4.30.0110.00616.53
7.4.00.0030.01014.96
7.3.330.0000.00613.46
7.3.320.0060.00013.38
7.3.310.0080.00016.41
7.3.300.0000.00716.52
7.3.290.0050.00916.48
7.3.280.0070.01216.47
7.3.270.0060.01017.40
7.3.260.0140.01116.64
7.3.250.0120.00616.51
7.3.240.0080.01416.60
7.3.230.0120.01216.66
7.3.210.0100.00716.63
7.3.200.0190.00316.54
7.3.190.0060.01116.50
7.3.180.0060.01016.43
7.3.170.0080.00816.64
7.3.160.0130.00616.59
7.3.10.0050.00816.58
7.3.00.0070.00416.27
7.2.330.0110.00716.46
7.2.320.0060.01216.40
7.2.310.0090.00916.57
7.2.300.0150.00616.57
7.2.290.0090.01216.73
7.2.130.0100.00616.72
7.2.120.0120.00416.50
7.2.110.0130.00316.59
7.2.100.0070.00816.41
7.2.90.0110.00716.49
7.2.80.0070.00916.68
7.2.70.0110.00916.72
7.2.60.0080.00916.80
7.2.50.0190.00616.55
7.2.40.0110.00616.31
7.2.30.0140.00716.77
7.2.20.0300.00816.53
7.2.10.0200.00816.70
7.2.00.0070.01117.73
7.1.250.0180.00615.69
7.1.200.0050.00315.52
7.1.100.0030.00918.23
7.1.70.0000.01116.86
7.1.60.0070.01719.11
7.1.50.0320.00434.56
7.1.00.0130.06722.27
7.0.200.0080.00016.79
7.0.90.0630.07020.07
7.0.80.0600.08019.96
7.0.70.0670.07319.99
7.0.60.0530.06020.07
7.0.50.0430.04720.41
7.0.40.0100.05320.13
7.0.30.0030.08720.11
7.0.20.0030.08719.95
7.0.10.0100.08020.02
7.0.00.0070.08320.16
5.6.280.0070.03720.88
5.6.240.0130.05320.53
5.6.230.0100.07720.67
5.6.220.0070.06720.70
5.6.210.0100.04320.79
5.6.200.0000.05321.13
5.6.190.0130.05721.01
5.6.180.0070.05021.09
5.6.170.0130.07721.02
5.6.160.0100.06721.10
5.6.150.0100.08321.11
5.6.140.0130.07721.07
5.6.130.0100.04021.02
5.6.120.0100.04321.15
5.6.110.0070.09021.07
5.6.100.0130.06721.03
5.6.90.0100.09021.14
5.6.80.0100.05320.59
5.6.70.0030.06020.29
5.6.60.0030.05720.33
5.6.50.0130.06320.52
5.6.40.0000.08320.34
5.6.30.0030.05720.40
5.6.20.0000.08720.48
5.6.10.0030.07720.45
5.6.00.0170.06020.38
5.5.380.0070.06320.46
5.5.370.0070.08020.48
5.5.360.0130.08020.36
5.5.350.0170.07020.47
5.5.340.0000.05320.89
5.5.330.0070.06720.66
5.5.320.0130.07720.85
5.5.310.0070.08020.78
5.5.300.0130.07320.89
5.5.290.0070.06720.85
5.5.280.0130.07320.92
5.5.270.0100.08020.80
5.5.260.0070.06720.89
5.5.250.0030.05320.59
5.5.240.0130.05320.20
5.5.230.0030.08020.26
5.5.220.0070.05720.04
5.5.210.0130.04320.31
5.5.200.0070.07320.20
5.5.190.0100.07720.30
5.5.180.0130.04720.20
5.5.160.0070.06020.26
5.5.150.0170.06720.27
5.5.140.0070.05320.29
5.5.130.0100.06320.00
5.5.120.0200.06320.25
5.5.110.0130.07020.29
5.5.100.0100.08020.11
5.5.90.0130.07320.18
5.5.80.0130.05020.08
5.5.70.0070.08020.08
5.5.60.0170.06720.17
5.5.50.0070.08320.14
5.5.40.0070.06020.05
5.5.30.0070.06320.12
5.5.20.0100.04720.10
5.5.10.0030.04020.05
5.5.00.0100.08020.09
5.4.450.0100.07719.27
5.4.440.0070.07719.27
5.4.430.0000.08019.47
5.4.420.0030.08319.53
5.4.410.0070.07719.15
5.4.400.0100.03718.97
5.4.390.0070.03719.03
5.4.380.0230.05319.23
5.4.370.0170.07019.18
5.4.360.0230.05719.04
5.4.350.0070.07719.25
5.4.340.0070.07718.96
5.4.320.0170.06719.23
5.4.310.0130.06718.95
5.4.300.0130.06319.23
5.4.290.0000.05318.90
5.4.280.0070.07319.04
5.4.270.0130.03719.13
5.4.260.0030.08019.16
5.4.250.0030.07319.20
5.4.240.0030.08019.04
5.4.230.0130.03719.12
5.4.220.0030.08318.90
5.4.210.0100.06319.17
5.4.200.0030.04019.12
5.4.190.0100.07319.15
5.4.180.0100.03018.93
5.4.170.0030.04319.02
5.4.160.0030.04319.01
5.4.150.0130.07318.93
5.4.140.0000.04316.16
5.4.130.0070.04716.44
5.4.120.0070.06716.36
5.4.110.0000.06316.55
5.4.100.0070.06316.44
5.4.90.0070.07716.42
5.4.80.0070.06716.27
5.4.70.0000.08316.47
5.4.60.0070.05716.46
5.4.50.0100.06316.41
5.4.40.0070.04016.30
5.4.30.0030.06016.41
5.4.20.0070.06016.46
5.4.10.0130.03716.48
5.4.00.0030.04715.86

preferences:
49.64 ms | 400 KiB | 5 Q