Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feature #35194 [Mailer] read default timeout from ini configurations …
…(azjezz)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Mailer] read default timeout from ini configurations

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #35138
| License       | MIT
| Doc PR        | n/a

```env
MAILER_DSN=mandrill+https://foo@default?timeout=30
```

Commits
-------

dafb057 [Mailer] read default timeout from ini configurations
  • Loading branch information
fabpot committed Jan 28, 2020
2 parents 3945a5c + dafb057 commit f0fbdee
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -26,7 +26,7 @@ final class SocketStream extends AbstractStream
private $url;
private $host = 'localhost';
private $port = 465;
private $timeout = 5;
private $timeout;
private $tls = true;
private $sourceIp;
private $streamContextOptions = [];
Expand All @@ -40,7 +40,7 @@ public function setTimeout(float $timeout): self

public function getTimeout(): float
{
return $this->timeout;
return $this->timeout ?? (float) ini_get('default_socket_timeout');
}

/**
Expand Down Expand Up @@ -134,17 +134,18 @@ public function initialize(): void
$options['ssl']['crypto_method'] = $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": %s.', $this->url, $msg));
});
try {
$this->stream = stream_socket_client($this->url, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $streamContext);
$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, $this->timeout);
stream_set_timeout($this->stream, $timeout);
$this->in = &$this->stream;
$this->out = &$this->stream;
}
Expand Down

0 comments on commit f0fbdee

Please sign in to comment.