45 $this->connectionTimeout = (float) ini_get(
'default_socket_timeout');
56 protected function write(array $record)
78 if (is_resource($this->resource)) {
79 fclose($this->resource);
80 $this->resource = null;
104 $this->connectionTimeout = (float) $seconds;
117 $this->timeout = (float) $seconds;
128 $this->writingTimeout = (float) $seconds;
138 $this->chunkSize = $bytes;
210 return is_resource($this->resource)
211 && !feof($this->resource);
219 return @
pfsockopen($this->connectionString, -1, $this->errno, $this->errstr, $this->connectionTimeout);
227 return @
fsockopen($this->connectionString, -1, $this->errno, $this->errstr, $this->connectionTimeout);
237 $seconds = floor($this->timeout);
238 $microseconds = round(($this->timeout - $seconds) * 1e6);
240 return stream_set_timeout($this->resource, $seconds, $microseconds);
250 return stream_set_chunk_size($this->resource, $this->chunkSize);
266 return stream_get_meta_data($this->resource);
271 $ok = filter_var($value, FILTER_VALIDATE_FLOAT);
272 if (
$ok ===
false || $value < 0) {
273 throw new \InvalidArgumentException(
"Timeout must be 0 or a positive float (got $value)");
287 return (
string) $record[
'formatted'];
313 throw new \UnexpectedValueException(
"Failed connecting to $this->connectionString ($this->errno: $this->errstr)");
321 throw new \UnexpectedValueException(
"Failed setting timeout with stream_set_timeout()");
328 throw new \UnexpectedValueException(
"Failed setting chunk size with stream_set_chunk_size()");
334 $length = strlen(
$data);
336 $this->lastSentBytes = $sent;
343 if ($chunk ===
false) {
344 throw new \RuntimeException(
"Could not write to socket");
348 if ($socketInfo[
'timed_out']) {
349 throw new \RuntimeException(
"Write timed-out");
353 throw new \RuntimeException(
"Write timed-out, no data sent for `{$this->writingTimeout}` seconds, probably we got disconnected (sent $sent of $length)");
357 throw new \RuntimeException(
"End-of-file reached, probably we got disconnected (sent $sent of $length)");
368 if ($sent !== $this->lastSentBytes) {
369 $this->lastWritingAt = time();
370 $this->lastSentBytes = $sent;
getChunkSize()
Get current chunk size.
getConnectionString()
Get current connection string.
const DEBUG
Detailed debug information.
setTimeout($seconds)
Set write timeout.
Stores to any socket - uses fsockopen() or pfsockopen().
setWritingTimeout($seconds)
Set writing timeout.
Base Handler class providing the Handler structure.
__construct($connectionString, $level=Logger::DEBUG, $bubble=true)
generateDataStream($record)
fwrite($data)
Wrapper to allow mocking.
isConnected()
Check to see if the socket is currently available.
write(array $record)
Connect (if necessary) and write to the socket.
fsockopen()
Wrapper to allow mocking.
close()
We will not close a PersistentSocket instance so it can be reused in other requests.
streamSetTimeout()
Wrapper to allow mocking.
isPersistent()
Get persistent setting.
setConnectionTimeout($seconds)
Set connection timeout.
pfsockopen()
Wrapper to allow mocking.
getWritingTimeout()
Get current local writing timeout.
setChunkSize($bytes)
Set chunk size.
getConnectionTimeout()
Get current connection timeout setting.
setPersistent($persistent)
Set socket connection to nbe persistent.
getTimeout()
Get current in-transfer timeout.
closeSocket()
Close socket, if open.
streamSetChunkSize()
Wrapper to allow mocking.
streamGetMetadata()
Wrapper to allow mocking.