Skip to content

Instantly share code, notes, and snippets.

@pekhota
Created January 4, 2018 14:32
Show Gist options
  • Save pekhota/9d44f900e46b2fdf2edee6c848adae8c to your computer and use it in GitHub Desktop.
Save pekhota/9d44f900e46b2fdf2edee6c848adae8c to your computer and use it in GitHub Desktop.
Пример того, как можно собирать метрики в едином месте.
<?php
function do($msg, callable $cb, array $params = []) {
$executionStartTime = microtime(true);
$result = call_user_func_array($cb, $params);
$executionEndTime = microtime(true);
$seconds = $executionEndTime - $executionStartTime;
event(new BlockOfCodeExecuted(
$msg,
$params,
$result,
$executionStartTime,
$executionEndTime
));
return $result;
}
@osadchyi-s
Copy link

$seconds = $executionEndTime - $executionStartTime;
Де потім юзається?

@igormartin
Copy link

// Call method
do($msg, [$this, 'someMethod'], $params);

@igormartin
Copy link

$result = $cb($params);

@osadchyi-s
Copy link

osadchyi-s commented Jan 5, 2018

Треба ще додати в BlockOfCodeExecuted імя $cb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment