1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-21 00:26:10 +02:00

Merge branch '1.x'

This commit is contained in:
Jordi Boggiano
2018-06-18 11:34:19 +02:00
3 changed files with 71 additions and 1 deletions

View File

@@ -30,6 +30,7 @@ class SocketHandler extends AbstractProcessingHandler
/** @var float */
private $writingTimeout = 10;
private $lastSentBytes = null;
private $chunkSize = null;
private $persistent = false;
private $errno;
private $errstr;
@@ -130,6 +131,16 @@ class SocketHandler extends AbstractProcessingHandler
$this->writingTimeout = (float) $seconds;
}
/**
* Set chunk size. Only has effect during connection in the writing cycle.
*
* @param float $bytes
*/
public function setChunkSize($bytes)
{
$this->chunkSize = $bytes;
}
/**
* Get current connection string
*
@@ -176,6 +187,16 @@ class SocketHandler extends AbstractProcessingHandler
return $this->writingTimeout;
}
/**
* Get current chunk size
*
* @return float
*/
public function getChunkSize()
{
return $this->chunkSize;
}
/**
* Check to see if the socket is currently available.
*
@@ -218,6 +239,16 @@ class SocketHandler extends AbstractProcessingHandler
return stream_set_timeout($this->resource, (int) $seconds, (int) $microseconds);
}
/**
* Wrapper to allow mocking
*
* @see http://php.net/manual/en/function.stream-set-chunk-size.php
*/
protected function streamSetChunkSize()
{
return stream_set_chunk_size($this->resource, $this->chunkSize);
}
/**
* Wrapper to allow mocking
*/
@@ -267,6 +298,7 @@ class SocketHandler extends AbstractProcessingHandler
{
$this->createSocketResource();
$this->setSocketTimeout();
$this->setStreamChunkSize();
}
private function createSocketResource()
@@ -289,6 +321,13 @@ class SocketHandler extends AbstractProcessingHandler
}
}
private function setStreamChunkSize()
{
if ($this->chunkSize && !$this->streamSetChunkSize()) {
throw new \UnexpectedValueException("Failed setting chunk size with stream_set_chunk_size()");
}
}
private function writeToSocket($data)
{
$length = strlen($data);