FetchData: Add time taken logging to response header

This commit is contained in:
Starbeamrainbowlabs 2019-01-14 22:18:30 +00:00
parent bbd08b439e
commit 66eeb9010d
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 17 additions and 2 deletions

View file

@ -1,4 +1,5 @@
<?php <?php
$start_time = microtime(true);
define("ROOT_DIR", dirname(__FILE__) . "/"); define("ROOT_DIR", dirname(__FILE__) . "/");

View file

@ -13,10 +13,24 @@ class FetchData {
$this->validator = new \AirQuality\Validator($_GET); $this->validator = new \AirQuality\Validator($_GET);
} }
public function handle() { public function handle() : Boolean {
global $start_time;
// 1: Validate params
$this->validator->is_datetime("datetime"); $this->validator->is_datetime("datetime");
$this->validator->run(); $this->validator->run();
echo("Params valid!"); // 2: Pull data from database
// 2.5: Validate data from database
// 3: Serialise data
$response = json_encode("Coming soon");
// 4: Send response
header("x-time-taken: " . (microtime(true) - $start_time) . "ms");
header("content-type: application/json");
echo($response);
return true;
} }
} }