44 $this->connectionTimeout = (float) ini_get(
'default_socket_timeout');
55 protected function write(array $record)
77 if (is_resource($this->resource)) {
78 fclose($this->resource);
79 $this->resource =
null;
103 $this->connectionTimeout = (float) $seconds;
116 $this->timeout = (float) $seconds;
127 $this->writingTimeout = (float) $seconds;
189 return is_resource($this->resource)
190 && !feof($this->resource);
198 return @
pfsockopen($this->connectionString, -1, $this->errno, $this->errstr, $this->connectionTimeout);
206 return @
fsockopen($this->connectionString, -1, $this->errno, $this->errstr, $this->connectionTimeout);
216 $seconds = floor($this->timeout);
217 $microseconds = round(($this->timeout - $seconds) * 1e6);
219 return stream_set_timeout($this->resource, $seconds, $microseconds);
235 return stream_get_meta_data($this->resource);
240 $ok = filter_var($value, FILTER_VALIDATE_FLOAT);
241 if (
$ok ===
false || $value < 0) {
242 throw new \InvalidArgumentException(
"Timeout must be 0 or a positive float (got $value)");
256 return (
string) $record[
'formatted'];
281 throw new \UnexpectedValueException(
"Failed connecting to $this->connectionString ($this->errno: $this->errstr)");
289 throw new \UnexpectedValueException(
"Failed setting timeout with stream_set_timeout()");
295 $length = strlen(
$data);
297 $this->lastSentBytes = $sent;
304 if ($chunk ===
false) {
305 throw new \RuntimeException(
"Could not write to socket");
309 if ($socketInfo[
'timed_out']) {
310 throw new \RuntimeException(
"Write timed-out");
314 throw new \RuntimeException(
"Write timed-out, no data sent for `{$this->writingTimeout}` seconds, probably we got disconnected (sent $sent of $length)");
318 throw new \RuntimeException(
"End-of-file reached, probably we got disconnected (sent $sent of $length)");
329 if ($sent !== $this->lastSentBytes) {
330 $this->lastWritingAt = time();
331 $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.
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.
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.
closeSocket()
Close socket, if open.
const DEBUG
Detailed debug information.