1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
<?php
namespace ICanBoogie\Routing;
use ICanBoogie\Binding\PrototypedBindings;
use ICanBoogie\HTTP\Request;
use ICanBoogie\Session;
class PingController extends Controller
{
use PrototypedBindings;
static private function format_time($finish)
{
return number_format(($finish - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 3, '.', '') . ' ms';
}
protected function action(Request $request)
{
$this->response->content_type = 'text/plain';
$session = $this->app->session;
if ($session->is_referenced)
{
$session->start_or_reuse();
}
$rc = 'pong';
if ($this->request['timer'] !== null)
{
$boot_time = self::format_time($_SERVER['ICANBOOGIE_READY_TIME_FLOAT']);
$run_time = self::format_time(microtime(true));
$rc .= ", in $run_time (ready in $boot_time)";
}
return $rc;
}
}