44 $this->connectionTimeout = (float) ini_get(
'default_socket_timeout');
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;
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.
Create styles array
The data for the language used.
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.
getConnectionTimeout()
Get current connection timeout setting.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
setPersistent($persistent)
Set socket connection to nbe persistent.
getTimeout()
Get current in-transfer timeout.
closeSocket()
Close socket, if open.
streamGetMetadata()
Wrapper to allow mocking.