Skip to content

Commit eeb39f7

Browse files
committed
Merge pull request #131 from F21/timetaken
Added time taken to the tracer.
2 parents 93f1b51 + fc16d91 commit eeb39f7

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/triagens/ArangoDb/Connection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ private function executeRequest($method, $url, $data)
350350
$handle = $this->getHandle();
351351
if ($handle) {
352352
// send data and get response back
353+
$startTime = microtime(true);
353354
$result = HttpHelper::transfer($handle, $request);
354-
355+
$timeTaken = microtime(true) - $startTime;
355356
$status = socket_get_status($handle);
356357

357358
if (!$this->_useKeepAlive) {
@@ -371,7 +372,7 @@ private function executeRequest($method, $url, $data)
371372
// call tracer func
372373
if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
373374
$traceFunc(
374-
new TraceResponse($response->getHeaders(), $response->getHttpCode(), $response->getBody())
375+
new TraceResponse($response->getHeaders(), $response->getHttpCode(), $response->getBody(), $timeTaken)
375376
);
376377
} else {
377378
$traceFunc('receive', $result);

lib/triagens/ArangoDb/TraceResponse.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class TraceResponse
4646
*/
4747
private $_type = "response";
4848

49+
/**
50+
* The time taken to send and receive a response in seconds
51+
* @var float
52+
*/
53+
private $_timeTaken;
54+
4955
/**
5056
* Used to look up the definition for an http code
5157
*
@@ -102,11 +108,12 @@ class TraceResponse
102108
* @param int $httpCode - the http code
103109
* @param string $body - the string of http body
104110
*/
105-
public function __construct($headers, $httpCode, $body)
111+
public function __construct($headers, $httpCode, $body, $timeTaken)
106112
{
107113
$this->_headers = $headers;
108114
$this->_httpCode = $httpCode;
109115
$this->_body = $body;
116+
$this->_timeTaken = $timeTaken;
110117
}
111118

112119
/**
@@ -163,4 +170,12 @@ public function getType()
163170
{
164171
return $this->_type;
165172
}
173+
174+
/**
175+
* Get the time taken for this request
176+
*/
177+
public function getTimeTaken()
178+
{
179+
return $this->_timeTaken;
180+
}
166181
}

tests/ConnectionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public function testEnhancedTracer()
145145
'Http code definition must be a string!'
146146
);
147147
$self->assertEquals('response', $data->getType());
148+
$self->assertInternalType('float', $data->getTimeTaken());
148149
}
149150
};
150151

0 commit comments

Comments
 (0)