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;
An exception for terminatinating execution or to throw for unit testing.
Base Handler class providing the Handler structure.
Stores to any socket - uses fsockopen() or pfsockopen().
setTimeout($seconds)
Set write timeout.
generateDataStream($record)
streamSetTimeout()
Wrapper to allow mocking.
fwrite($data)
Wrapper to allow mocking.
write(array $record)
Connect (if necessary) and write to the socket.
streamSetChunkSize()
Wrapper to allow mocking.
getWritingTimeout()
Get current local writing timeout.
isConnected()
Check to see if the socket is currently available.
pfsockopen()
Wrapper to allow mocking.
fsockopen()
Wrapper to allow mocking.
getConnectionString()
Get current connection string.
setChunkSize($bytes)
Set chunk size.
setConnectionTimeout($seconds)
Set connection timeout.
close()
We will not close a PersistentSocket instance so it can be reused in other requests.
getConnectionTimeout()
Get current connection timeout setting.
streamGetMetadata()
Wrapper to allow mocking.
setPersistent($persistent)
Set socket connection to nbe persistent.
__construct($connectionString, $level=Logger::DEBUG, $bubble=true)
isPersistent()
Get persistent setting.
getTimeout()
Get current in-transfer timeout.
setWritingTimeout($seconds)
Set writing timeout.
getChunkSize()
Get current chunk size.
closeSocket()
Close socket, if open.
const DEBUG
Detailed debug information.