-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.php
40 lines (33 loc) · 813 Bytes
/
log.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
37
38
39
40
<?php
class Logger
{
protected static $instance = null;
const path = "./log.sock";
public function __construct()
{
$this->socket = socket_create(AF_UNIX, SOCK_STREAM, 1);
socket_set_nonblock($this->socket);
socket_connect($this->socket, self::path);
}
public function __destruct()
{
socket_close($this->socket);
}
public function send($item)
{
$payload = json_encode($item);
socket_write($this->socket, $payload);
}
protected function __clone()
{
//Prevent new instances
}
public static function log($item)
{
if (!isset(static::$instance)) {
static::$instance = new static;
}
return (static::$instance)->send($item);
}
}
Logger::log([1, "foo"]);