Skip to content

Commit

Permalink
add X-LitCal-ExecutionTime header
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Mar 25, 2024
1 parent 1731db0 commit 0965b8c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions includes/LitCalAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class LitCalAPI {
private string $BaptismLordFmt;
private string $BaptismLordMod;

private int $startTime = hrtime(true);
private int $endTime;

/**
* The following schemas for ordinal spellouts have been taken from
* https://www.saxonica.com/html/documentation11/extensibility/localizing/ICU-numbering-dates/ICU-numbering.html
Expand Down Expand Up @@ -2808,6 +2811,7 @@ private function generateResponse() {
$SerializeableLitCal->Metadata->VERSION = self::API_VERSION;
$SerializeableLitCal->Metadata->Timestamp = time();
$SerializeableLitCal->Metadata->DateTime = date('Y-m-d H:i:s');

//$SerializeableLitCal->Metadata->RequestHeaders = $this->APICore->getJsonEncodedRequestHeaders();
$SerializeableLitCal->Metadata->RequestHeaders = $this->APICore->getRequestHeaders();
$SerializeableLitCal->Metadata->Solemnities = $this->Cal->getSolemnities();
Expand Down Expand Up @@ -2844,6 +2848,11 @@ private function generateResponse() {
}
file_put_contents( $this->CACHEFILE, $response );
$responseHash = md5( $response );

$this->endTime = hrtime(true);
$executionTime = $this->endTime - $this->startTime;
header('X-LitCal-ExecutionTime: ' . $executionTime);

header("Etag: \"{$responseHash}\"");
if (!empty( $_SERVER['HTTP_IF_NONE_MATCH'] ) && $_SERVER['HTTP_IF_NONE_MATCH'] === $responseHash) {
header( $_SERVER[ "SERVER_PROTOCOL" ] . " 304 Not Modified" );
Expand Down Expand Up @@ -2917,8 +2926,13 @@ public function Init(){
//and stored the results in a cache file
//then we're done, just output this and die
//or better, make the client use it's own cache copy!
$response = file_get_contents( $this->CACHEFILE );
$responseHash = md5( $response );
$response = file_get_contents( $this->CACHEFILE );
$responseHash = md5( $response );

$this->endTime = hrtime(true);
$executionTime = $this->endTime - $this->startTime;
header('X-LitCal-ExecutionTime: ' . $executionTime);

header("Etag: \"{$responseHash}\"");
if (!empty( $_SERVER['HTTP_IF_NONE_MATCH'] ) && $_SERVER['HTTP_IF_NONE_MATCH'] === $responseHash) {
header( $_SERVER[ "SERVER_PROTOCOL" ] . " 304 Not Modified" );
Expand Down

0 comments on commit 0965b8c

Please sign in to comment.