41 $this->connectionTimeout = (float) ini_get(
'default_socket_timeout');
52 protected function write(array $record)
74 if (is_resource($this->resource)) {
75 fclose($this->resource);
76 $this->resource = null;
87 $this->persistent = (boolean) $boolean;
100 $this->connectionTimeout = (float) $seconds;
113 $this->timeout = (float) $seconds;
165 return is_resource($this->resource)
166 && !feof($this->resource);
174 return @
pfsockopen($this->connectionString, -1, $this->errno, $this->errstr, $this->connectionTimeout);
182 return @
fsockopen($this->connectionString, -1, $this->errno, $this->errstr, $this->connectionTimeout);
192 $seconds = floor($this->timeout);
193 $microseconds = round(($this->timeout - $seconds)*1e6);
195 return stream_set_timeout($this->resource, $seconds, $microseconds);
211 return stream_get_meta_data($this->resource);
216 $ok = filter_var($value, FILTER_VALIDATE_FLOAT);
217 if (
$ok ===
false || $value < 0) {
218 throw new \InvalidArgumentException(
"Timeout must be 0 or a positive float (got $value)");
232 return (
string) $record[
'formatted'];
249 throw new \UnexpectedValueException(
"Failed connecting to $this->connectionString ($this->errno: $this->errstr)");
257 throw new \UnexpectedValueException(
"Failed setting timeout with stream_set_timeout()");
263 $length = strlen(
$data);
271 if ($chunk ===
false) {
272 throw new \RuntimeException(
"Could not write to socket");
276 if ($socketInfo[
'timed_out']) {
277 throw new \RuntimeException(
"Write timed-out");
281 throw new \RuntimeException(
"End-of-file reached, probably we got disconnected (sent $sent of $length)");
getConnectionString()
Get current connection string.
const DEBUG
Detailed debug information.
setTimeout($seconds)
Set write timeout.
Stores to any socket - uses fsockopen() or pfsockopen().
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.
setPersistent($boolean)
Set socket connection to nbe persistent.
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.
getConnectionTimeout()
Get current connection timeout setting.
getTimeout()
Get current in-transfer timeout.
closeSocket()
Close socket, if open.
streamGetMetadata()
Wrapper to allow mocking.