Livestatus\Connection: benchmark, comments

This commit is contained in:
Thomas Gelf 2014-11-16 17:59:56 +01:00
parent 140b246974
commit 2c7373f385
1 changed files with 10 additions and 0 deletions

View File

@ -354,15 +354,22 @@ if ($col > $size - 1) return $res;
protected function getConnection() protected function getConnection()
{ {
if ($this->connection === null) { if ($this->connection === null) {
Benchmark::measure('Establishing livestatus connection...');
if ($this->socket_type === self::TYPE_TCP) { if ($this->socket_type === self::TYPE_TCP) {
$this->establishTcpConnection(); $this->establishTcpConnection();
Benchmark::measure('...got TCP socket');
} else { } else {
$this->establishSocketConnection(); $this->establishSocketConnection();
Benchmark::measure('...got local socket');
} }
} }
return $this->connection; return $this->connection;
} }
/**
* Establish a TCP socket connection
*/
protected function establishTcpConnection() protected function establishTcpConnection()
{ {
$this->connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $this->connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
@ -377,6 +384,9 @@ if ($col > $size - 1) return $res;
socket_set_option($this->connection, SOL_TCP, TCP_NODELAY, 1); socket_set_option($this->connection, SOL_TCP, TCP_NODELAY, 1);
} }
/**
* Establish a UNIX socket connection
*/
protected function establishSocketConnection() protected function establishSocketConnection()
{ {
$this->connection = socket_create(AF_UNIX, SOCK_STREAM, 0); $this->connection = socket_create(AF_UNIX, SOCK_STREAM, 0);