function Connection::write
File
-
vendor/
symfony/ var-dumper/ Server/ Connection.php, line 51
Class
- Connection
- Forwards serialized Data clones to a server.
Namespace
Symfony\Component\VarDumper\ServerCode
public function write(Data $data) : bool {
$socketIsFresh = !$this->socket;
if (!($this->socket = $this->socket ?: $this->createSocket())) {
return false;
}
$context = [
'timestamp' => microtime(true),
];
foreach ($this->contextProviders as $name => $provider) {
$context[$name] = $provider->getContext();
}
$context = array_filter($context);
$encodedPayload = base64_encode(serialize([
$data,
$context,
])) . "\n";
set_error_handler(static fn() => null);
try {
if (-1 !== stream_socket_sendto($this->socket, $encodedPayload)) {
return true;
}
if (!$socketIsFresh) {
stream_socket_shutdown($this->socket, \STREAM_SHUT_RDWR);
fclose($this->socket);
$this->socket = $this->createSocket();
}
if (-1 !== stream_socket_sendto($this->socket, $encodedPayload)) {
return true;
}
} finally {
restore_error_handler();
}
return false;
}