Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Connection.php

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\Server

Code

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;
}
RSS feed
Powered by Drupal