@@ -116,6 +116,20 @@ abstract class REST_Controller extends CI_Controller
116116 */
117117 protected $ _user_ldap_dn = '' ;
118118
119+ /**
120+ * The start of the response time from the server
121+ *
122+ * @var string
123+ */
124+ protected $ _start_rtime = '' ;
125+
126+ /**
127+ * The end of the response time from the server
128+ *
129+ * @var string
130+ */
131+ protected $ _end_rtime = '' ;
132+
119133 /**
120134 * List all supported methods, the first will be the default format
121135 *
@@ -146,7 +160,10 @@ protected function early_checks()
146160 public function __construct ()
147161 {
148162 parent ::__construct ();
149-
163+
164+ // Start the timer for how long the request takes
165+ $ this ->_start_rtime = microtime (TRUE );
166+
150167 // init objects
151168 $ this ->request = new stdClass ();
152169 $ this ->response = new stdClass ();
@@ -253,6 +270,23 @@ public function __construct()
253270 }
254271 }
255272
273+ /**
274+ * Destructor function
275+ * @author Chris Kacerguis
276+ */
277+ public function __destruct ()
278+ {
279+ // Record the "stop" time of the request
280+ $ this ->_end_rtime = microtime (TRUE );
281+ // CK: if, we are logging, log the access time here, as we are done!
282+ if (config_item ('rest_enable_logging ' ))
283+ {
284+ $ this ->_log_access_time ();
285+ }
286+
287+
288+ }
289+
256290 /**
257291 * Remap
258292 *
@@ -1256,6 +1290,21 @@ protected function _force_loopable($data)
12561290 return $ data ;
12571291 }
12581292
1293+ /**
1294+ * updates the log with the access time
1295+ *
1296+ * @author Chris Kacerguis
1297+ * @return boolean
1298+ */
1299+
1300+ protected function _log_access_time ()
1301+ {
1302+ $ payload ['rtime ' ] = $ this ->_end_rtime - $ this ->_start_rtime ;
1303+ return $ this ->rest ->db ->update (config_item ('rest_logs_table ' ), $ payload , array ('id ' => $ this ->_insert_id ));
1304+ }
1305+
1306+
1307+
12591308 // FORMATING FUNCTIONS ---------------------------------------------------------
12601309 // Many of these have been moved to the Format class for better separation, but these methods will be checked too
12611310
0 commit comments