I would like in the fatfree framework to log all the endpoints and files that are run one by one and save this in the logs in the database. What is the best way to do this?
Now, I have this code:
private function debugBacktrace() {
$base = Base::instance()->get('dba');
$data = debug_backtrace();
foreach ($data as $row) {
$file = $row['file'] ?? null;
$function = $row['function'] ?? null;
$class = $row['class'] ?? null;
$date = new DateTime();
$dateFormatted = $date->format('Y-m-d H:i:s');
$existRecord = $base->exec("SELECT * FROM `pholus`.`debug_trace` WHERE `file` = '$file' AND `function` = '$function' AND `class` = '$class'");
if (!empty($existRecord)) {
$id = $existRecord[0]['id'];
$count = $existRecord[0]['count']+1;
$base->exec("UPDATE `pholus`.`debug_trace` SET `count` = $count, `last_update` = '$dateFormatted' WHERE `id` = $id;");
} else {
$base->exec("INSERT INTO `pholus`.`debug_trace` (`file`, `function`, `class`, `count`, `last_update`)
VALUES ('$file', '$function', '$class', 1, '$dateFormatted');");
}
}
}
And results:
The only question is whether this is the optimal solution? I don’t see any templates launched here (only php files). Does f3 have any native profiling solution?
2
Answers
So no, I think with what you’re after, there currently isn’t Fat-Free functionality like that.
I did create an extension that hooks into the Tracy Debug bar that may be of interest to you. https://github.com/n0nag0n/fatfree-tracy-extensions. I do some level of what you’re asking for with trying to capture which templates get rendered, which db queries were run, and the endpoint that’s hit. Maybe it’ll point you in the direction you need?
You can use xdebug profiling and webgrind to capture and analyse application execution.