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

Breadcrumb

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

function SocketStream::initialize

Overrides AbstractStream::initialize

File

vendor/symfony/mailer/Transport/Smtp/Stream/SocketStream.php, line 135

Class

SocketStream
A stream supporting remote sockets.

Namespace

Symfony\Component\Mailer\Transport\Smtp\Stream

Code

public function initialize() : void {
    $this->url = $this->host . ':' . $this->port;
    if ($this->tls) {
        $this->url = 'ssl://' . $this->url;
    }
    $options = [];
    if ($this->sourceIp) {
        $options['socket']['bindto'] = $this->sourceIp . ':0';
    }
    if ($this->streamContextOptions) {
        $options = array_merge($options, $this->streamContextOptions);
    }
    // do it unconditionally as it will be used by STARTTLS as well if supported
    $options['ssl']['crypto_method'] ??= \STREAM_CRYPTO_METHOD_TLS_CLIENT | \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT | \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
    $streamContext = stream_context_create($options);
    $timeout = $this->getTimeout();
    set_error_handler(function ($type, $msg) {
        throw new TransportException(\sprintf('Connection could not be established with host "%s": ', $this->url) . $msg);
    });
    try {
        $this->stream = stream_socket_client($this->url, $errno, $errstr, $timeout, \STREAM_CLIENT_CONNECT, $streamContext);
    } finally {
        restore_error_handler();
    }
    stream_set_blocking($this->stream, true);
    stream_set_timeout($this->stream, (int) $timeout, (int) (($timeout - (int) $timeout) * 1000000));
    $this->in =& $this->stream;
    $this->out =& $this->stream;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal