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)");
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.
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($boolean)
Set socket connection to nbe persistent.
__construct($connectionString, $level=Logger::DEBUG, $bubble=true)
isPersistent()
Get persistent setting.
getTimeout()
Get current in-transfer timeout.
closeSocket()
Close socket, if open.
const DEBUG
Detailed debug information.