-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAudit.php
36 lines (34 loc) · 829 Bytes
/
Audit.php
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
<?php
namespace core;
class AuditSync
{
private $pfx; // Prefix text in case of msg
private $time; // time()
private $max; // max time in minutes before destruct is called
public function __construct($pfx, $max)
{
$this->time = time();
$this->pfx = $pfx;
$this->max = $max;
}
public function __destruct()
{
$diff = round(abs(time() - $this->time) / 60, 2);
if ($diff > $this->max) {
error_log(sprintf("perf.warn(%s) max.passed.seconds (dur=%s max=%s)", $this->pfx, $diff, $this->max));
}
if (VERBOSE) {
error_log(sprintf("per.debug(%s) time.passed.seconds (dur=%s max=%s)", $this->pfx, $diff, $this->max));
}
}
}
/** Simple code auditting */
class Audit
{
public static function perf($prefix, $max)
{
global $EXITHACK;
$EXITHACK = new AuditSync($prefix, $max);
return true;
}
}