3v4l.org

run code in 300+ PHP versions simultaneously
<?php use Tonic\Resource, Tonic\Response, Tonic\ConditionException; /** * Class to add, update and remove Meals * @uri /eatLogs/logs/{date}/meals */ class EatLogMeals extends EatLogs { /* { "id":1, "servings":2, "mealoccasion_id":4, "is_eat_out":true } */ /** * Add new Meal - return the whole eat log (/eatLogs/logs/{date}/meals) * @method POST * @provides application/json * @secure basic * @return Response */ function addEatLogMeal() { global $app; $user = $this->getUser(); //check if date is in correct format yyyyMMdd $this->date = $this->validateDate($this->date); //TODO validate other input //find a plan for current user $plan = $user->getPlan(); if(!$plan || !$plan->id) { throw new Tonic\NotFoundException('EatLogMeal couldn\'t be created. Plan for current user not found'); } $eatLog = R::findOne('eatlog', ' plan_id = ? AND log_date = ?', array($plan->id, $this->date)); //eatlog exists? if (!$eatLog || !$eatLog->id) { //create a EatLog entry $eatLog = $this->createEatLog($plan); } //meal exists? $meal = R::load('meal', $this->request->data['id']); if (!$meal || !$meal->id) { throw new Tonic\NotFoundException('EatLogMeal couldn\'t be created. Meal with id ' . $this->request->data['id'] . ' not found.'); } //meal occasion exists? $mealOccasion = R::load('mealoccasion', $this->request->data['mealoccasion_id']); if (!$mealOccasion || !$mealOccasion->id) { throw new Tonic\NotFoundException('EatLogMeal couldn\'t be created. Meal occasion with id ' . $this->request->data['mealoccasion_id'] . ' not found.'); } if ($this->request->data['servings'] > 0) { //insert EatLogMeals - as many as servings argument $items = array(); /* if ($this->request->data->servings > 1) { $items = R::dispense('eatlogmeal', $this->request->data->servings); } else { $items[0] = R::dispense('eatlogmeal'); } */ for ($i = 0; $i < $this->request->data['servings']; $i++) { $item = R::dispense('eatlogmeal'); $item->eatlog = $eatLog; $item->meal = $meal; $item->mealoccasion = $mealOccasion; $item->is_eat_out = (bool) $this->request->data['is_eat_out']; $eatLogMealId = R::store($item); //add EatLogItems for this Meal $mealImpactGroup = R::find('mealimpactgroup', ' meal_id = :meal_id', array(':meal_id' => $meal->id)); foreach ($mealImpactGroup as $mIG) { //insert EatLogItems - as many as servings argument $items2 = array(); if ($mIG->servings > 1) { $items2 = R::dispense('eatlogitem', $mIG->servings); } else { $items2[0] = R::dispense('eatlogitem'); } for ($j = 0; $j < $mIG->servings; $j++) { $items2[$j]->eatlog = $eatLog; $items2[$j]->eatimpactgroup_id = $mIG->eatimpactgroup_id; $items2[$j]->mealoccasion = $mealOccasion; $items2[$j]->is_eat_out = $this->request->data['is_eat_out']; $items2[$j]->eatlogmeal = $item; } R::storeAll($items2); } } //R::storeAll($items); } //calculate total impact factor $this->calculateTotalImpactFactor($eatLog, $plan->program_id); return $this->listEatLog(); } /** * Remove EatLogMeal(s) (/eatLogs/logs/{date}/meals) - return the whole eat log * @method DELETE * @provides application/json * @secure basic * @return Response */ function removeEatLogMeals() { $user = $this->getUser(); //check if date is in correct format yyyyMMdd $this->date = $this->validateDate($this->date); //TODO validate other input //find a plan for current user $plan = $user->getPlan(); if(!$plan || !$plan->id) { throw new Tonic\NotFoundException('EatLog couldn\'t be created. Plan for current user not found'); } $eatLog = R::findOne('eatlog', ' plan_id = ? AND log_date = ?', array($plan->id, $this->date)); //eatlog exists? if (!$eatLog || !$eatLog->id) { //create a EatLog entry $eatLog = $this->createEatLog($plan); } if ($this->request->data['servings'] > 0) { //TODO check whether there are actually those eatlogmeals? R::exec("DELETE FROM eatlogmeal WHERE eatlog_id = :eatlog_id AND meal_id = :meal_id AND mealoccasion_id = :mealoccasion_id AND is_eat_out = :is_eat_out LIMIT :servings", array( ':eatlog_id' => $eatLog->id, ':meal_id' => $this->request->data['id'], ':mealoccasion_id' => $this->request->data['mealoccasion_id'], ':is_eat_out' => $this->request->data['is_eat_out'], ':servings' => $this->request->data['servings'] )); //any EatLogItems associated with this meal are deleted thanks to ON DELETE CASCADE constraint on eatlogmeal_id foreign key in eatlogitme table } $this->calculateTotalImpactFactor($eatLog, $plan->program_id); return $this->listEatLog(); //return new Response(Response::NOCONTENT); } }

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.0070.01418.43
8.3.50.0100.00721.99
8.3.40.0130.00918.96
8.3.30.0140.00719.21
8.3.20.0070.00020.21
8.3.10.0050.00322.07
8.3.00.0040.00422.21
8.2.180.0080.00816.75
8.2.170.0070.00722.96
8.2.160.0060.01520.74
8.2.150.0060.00324.18
8.2.140.0050.00324.66
8.2.130.0070.00026.16
8.2.120.0080.00017.88
8.2.110.0070.00320.65
8.2.100.0100.00317.78
8.2.90.0040.00419.30
8.2.80.0060.00317.97
8.2.70.0030.00617.75
8.2.60.0080.00018.15
8.2.50.0060.00318.07
8.2.40.0100.00018.22
8.2.30.0000.00818.10
8.2.20.0050.00317.72
8.2.10.0040.00417.82
8.2.00.0040.00417.83
8.1.280.0150.00625.92
8.1.270.0050.00323.96
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0000.01022.32
8.1.230.0060.00617.51
8.1.220.0030.00517.91
8.1.210.0080.00018.77
8.1.200.0000.00917.46
8.1.190.0040.00417.65
8.1.180.0040.00418.10
8.1.170.0060.00318.79
8.1.160.0040.00421.98
8.1.150.0080.00018.55
8.1.140.0000.00917.39
8.1.130.0050.00217.73
8.1.120.0070.00017.51
8.1.110.0000.00817.50
8.1.100.0040.00417.53
8.1.90.0050.00517.38
8.1.80.0020.00517.54
8.1.70.0000.00717.49
8.1.60.0080.00417.58
8.1.50.0030.00617.55
8.1.40.0000.00817.58
8.1.30.0040.00417.57
8.1.20.0080.00017.70
8.1.10.0030.00517.56
8.1.00.0050.00317.58
8.0.300.0080.00018.77
8.0.290.0000.00816.88
8.0.280.0000.00718.58
8.0.270.0040.00417.36
8.0.260.0000.00616.98
8.0.250.0030.00517.16
8.0.240.0000.00717.11
8.0.230.0040.00417.08
8.0.220.0050.00317.11
8.0.210.0000.00717.02
8.0.200.0030.00317.15
8.0.190.0040.00417.06
8.0.180.0070.00016.93
8.0.170.0030.00517.05
8.0.160.0080.00017.03
8.0.150.0050.00317.01
8.0.140.0000.00716.98
8.0.130.0030.00313.48
8.0.120.0040.00416.90
8.0.110.0040.00416.93
8.0.100.0070.00017.05
8.0.90.0000.00716.96
8.0.80.0130.01016.95
8.0.70.0040.00417.11
8.0.60.0040.00417.09
8.0.50.0000.00816.93
8.0.30.0110.00817.17
8.0.20.0120.00617.40
8.0.10.0050.00317.04
8.0.00.0070.01416.88
7.4.330.0020.00215.00
7.4.320.0030.00316.67
7.4.300.0030.00316.48
7.4.290.0070.00016.60
7.4.280.0060.00316.55
7.4.270.0000.00716.57
7.4.260.0070.00016.54
7.4.250.0040.00416.58
7.4.240.0020.00616.63
7.4.230.0070.00016.52
7.4.220.0110.00716.58
7.4.210.0050.01116.63
7.4.200.0040.00416.43
7.4.190.0000.00816.68
7.4.160.0110.00416.59
7.4.150.0030.01317.40
7.4.140.0090.01117.86
7.4.130.0050.01516.58
7.4.120.0060.01116.51
7.4.110.0130.00616.43
7.4.100.0070.01016.32
7.4.90.0000.02016.81
7.4.80.0070.01816.54
7.4.70.0040.01416.81
7.4.60.0100.01016.52
7.4.50.0030.00316.46
7.4.40.0030.01022.77
7.4.30.0130.00316.59
7.4.00.0070.00714.71
7.3.330.0030.00313.42
7.3.320.0030.00313.42
7.3.310.0040.00416.27
7.3.300.0040.00416.41
7.3.290.0110.00716.41
7.3.280.0120.00716.41
7.3.270.0150.00317.40
7.3.260.0130.00616.62
7.3.250.0120.00516.53
7.3.240.0120.00616.46
7.3.230.0070.01716.39
7.3.210.0130.00916.48
7.3.200.0070.01019.39
7.3.190.0030.01316.60
7.3.180.0030.01316.39
7.3.170.0100.01016.55
7.3.160.0120.00916.55
7.3.120.0060.01015.20
7.3.110.0060.00314.92
7.3.100.0030.00614.90
7.3.90.0070.00715.08
7.3.80.0110.00414.88
7.3.70.0080.00914.96
7.3.60.0090.00614.86
7.3.50.0030.01414.89
7.3.40.0060.00915.04
7.3.30.0100.00714.64
7.3.20.0140.00316.85
7.3.10.0070.00716.52
7.3.00.0100.00716.21
7.2.330.0120.00916.46
7.2.320.0160.00616.56
7.2.310.0030.02016.50
7.2.300.0130.00916.31
7.2.290.0120.00616.47
7.2.240.0000.01414.80
7.2.230.0090.00615.18
7.2.220.0100.00315.11
7.2.210.0000.01514.94
7.2.200.0080.00814.86
7.2.190.0060.00814.68
7.2.180.0070.01014.79
7.2.170.0040.01415.03
7.2.160.0040.01414.68
7.2.150.0060.00616.84
7.2.140.0030.01416.36
7.2.130.0100.00316.84
7.2.120.0040.01116.83
7.2.110.0000.01716.66
7.2.100.0090.00316.73
7.2.90.0070.01016.82
7.2.80.0030.01216.52
7.2.70.0110.00316.77
7.2.60.0040.01216.77
7.2.50.0060.00916.95
7.2.40.0000.01216.79
7.2.30.0000.01716.60
7.2.20.0100.00716.73
7.2.10.0000.01216.48
7.2.00.0050.01117.93
7.1.330.0070.00715.63
7.1.320.0070.01015.83
7.1.310.0030.00715.75
7.1.300.0000.01615.61
7.1.290.0080.00315.71
7.1.280.0030.00915.52
7.1.270.0070.01015.41
7.1.260.0060.00615.61
7.1.250.0000.01615.74
7.1.100.0030.01417.99
7.1.70.0050.00216.99
7.1.60.0120.00919.82
7.1.50.0110.01116.86
7.1.00.0030.07722.32
7.0.200.0030.01016.54
7.0.140.0030.07322.17
7.0.60.0070.05020.13
7.0.50.0070.04018.03
7.0.40.0030.04720.25
7.0.30.0330.04320.07
7.0.20.0400.07020.05
7.0.10.0030.07320.25
7.0.00.0200.06320.12
5.6.280.0070.07020.95
5.6.210.0130.03320.55
5.6.200.0000.05018.29
5.6.190.0070.04320.52
5.6.180.3930.04320.55
5.6.170.0230.07720.62
5.6.160.0070.04020.46
5.6.150.0070.03718.25
5.6.140.0000.08018.18
5.6.130.0100.05018.19
5.6.120.0100.08320.94
5.6.110.0070.08721.02
5.6.100.0000.04320.90
5.6.90.0100.03721.00
5.6.80.0030.08320.42
5.5.350.0200.08020.42
5.5.340.0170.06718.01
5.5.330.0070.08320.27
5.5.320.0130.08320.37
5.5.310.0170.04720.41
5.5.300.0100.06018.00
5.5.290.0070.08717.99
5.5.280.0070.08720.78
5.5.270.0000.06720.81
5.5.260.0030.08321.00
5.5.250.0030.04720.73
5.5.240.0000.06020.20
5.4.450.0370.05719.49
5.4.440.0270.06719.34
5.4.430.1200.03719.63
5.4.420.0570.04019.63
5.4.410.0200.04019.41
5.4.400.0100.04319.16
5.4.390.0200.03019.09
5.4.380.0400.05318.57
5.4.370.0400.05018.54
5.4.360.0270.05718.57
5.4.350.0530.04318.61
5.4.340.0370.05018.73
5.4.320.0050.04212.54
5.4.310.0080.03712.54
5.4.300.0040.03912.54
5.4.290.0070.03712.54
5.4.280.0130.06912.41
5.4.270.0070.05612.41
5.4.260.0170.04512.41
5.4.250.0060.04012.41
5.4.240.0060.04212.41
5.4.230.0080.04712.40
5.4.220.0020.04712.40
5.4.210.0100.04412.41
5.4.200.0080.05012.41
5.4.190.0070.03712.39
5.4.180.0030.04212.39
5.4.170.0070.03912.41
5.4.160.0040.04012.40
5.4.150.0050.04312.40
5.4.140.0050.04512.09
5.4.130.0060.03512.07
5.4.120.0050.04312.04
5.4.110.0090.03812.02
5.4.100.0090.04012.03
5.4.90.0050.04712.03
5.4.80.0070.04312.03
5.4.70.0090.04612.02
5.4.60.0050.05112.02
5.4.50.0110.03612.02
5.4.40.0080.03612.01
5.4.30.0050.04112.00
5.4.20.0130.04212.00
5.4.10.0080.05212.00
5.4.00.0070.04511.49
5.3.290.0070.04212.80
5.3.280.0100.04612.71
5.3.270.0070.04212.72
5.3.260.0060.04412.72
5.3.250.0080.03812.72
5.3.240.0070.03912.72
5.3.230.0070.04112.71
5.3.220.0040.04312.68
5.3.210.0060.04612.68
5.3.200.0090.03812.68
5.3.190.0090.04112.68
5.3.180.0070.04212.67
5.3.170.0120.03512.67
5.3.160.0100.03912.67
5.3.150.0050.04312.67
5.3.140.0070.04412.66
5.3.130.0100.05012.66
5.3.120.0100.05012.66
5.3.110.0070.04412.66
5.3.100.0070.05112.13
5.3.90.0090.05312.12
5.3.80.0070.05012.10
5.3.70.0070.05112.10
5.3.60.0110.04512.09
5.3.50.0060.04112.03
5.3.40.0040.05012.04
5.3.30.0070.04411.99
5.3.20.0050.04011.77
5.3.10.0090.03711.74
5.3.00.0110.04811.73
5.2.170.0070.0419.16
5.2.160.0050.0439.16
5.2.150.0090.0409.16
5.2.140.0030.0509.16
5.2.130.0050.0419.11
5.2.120.0070.0389.12
5.2.110.0070.0329.12
5.2.100.0060.0289.12
5.2.90.0050.0309.12
5.2.80.0070.0289.11
5.2.70.0050.0319.11
5.2.60.0070.0299.06
5.2.50.0080.0289.04
5.2.40.0030.0329.01
5.2.30.0050.0318.99
5.2.20.0040.0338.97
5.2.10.0020.0328.91
5.2.00.0060.0458.76
5.1.60.0070.0228.05
5.1.50.0040.0318.05
5.1.40.0040.0298.03
5.1.30.0060.0258.38
5.1.20.0070.0278.40
5.1.10.0050.0288.13
5.1.00.0080.0288.13
5.0.50.0050.0326.60
5.0.40.0060.0276.46
5.0.30.0050.0326.27
5.0.20.0010.0236.25
5.0.10.0020.0346.22
5.0.00.0060.0406.21
4.4.90.0030.0254.78
4.4.80.0030.0234.76
4.4.70.0050.0214.75
4.4.60.0040.0234.75
4.4.50.0020.0254.77
4.4.40.0050.0354.71
4.4.30.0050.0224.76
4.4.20.0050.0234.85
4.4.10.0040.0224.84
4.4.00.0020.0344.76
4.3.110.0040.0224.67
4.3.100.0080.0474.66
4.3.90.0020.0284.63
4.3.80.0070.0364.59
4.3.70.0060.0234.63
4.3.60.0030.0184.63
4.3.50.0030.0164.63
4.3.40.0020.0274.54
4.3.30.0020.0173.27
4.3.20.0000.0193.26
4.3.10.0010.0183.22
4.3.00.0030.01313.14

preferences:
35.27 ms | 401 KiB | 5 Q