Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stream_flags option #66

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 2.1.2

* add `stream_flags` option

## 2.1.1

* Fixed constructor to work nicely with version 1 style arguments (e.g. HttplugBundle)
Expand Down
8 changes: 5 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function createSocket(RequestInterface $request, string $remote, bool
{
$errNo = null;
$errMsg = null;
$socket = @stream_socket_client($remote, $errNo, $errMsg, floor($this->config['timeout'] / 1000), STREAM_CLIENT_CONNECT, $this->config['stream_context']);
$socket = @stream_socket_client($remote, $errNo, $errMsg, floor($this->config['timeout'] / 1000), STREAM_CLIENT_CONNECT | $this->config['stream_flags'], $this->config['stream_context']);

if (false === $socket) {
if (110 === $errNo) {
Expand Down Expand Up @@ -142,9 +142,9 @@ protected function closeSocket($socket)
/**
* Return configuration for the socket client.
*
* @param array{remote_socket?: string|null, timeout?: int, stream_context?: resource, stream_context_options?: array<string, mixed>, stream_context_param?: array<string, mixed>, ssl?: ?boolean, write_buffer_size?: int, ssl_method?: int} $config
* @param array{remote_socket?: string|null, timeout?: int, stream_context?: resource, stream_context_options?: array<string, mixed>, stream_context_param?: array<string, mixed>, stream_flags: ?int, ssl?: ?boolean, write_buffer_size?: int, ssl_method?: int} $config
*
* @return array{remote_socket: string|null, timeout: int, stream_context: resource, stream_context_options: array<string, mixed>, stream_context_param: array<string, mixed>, ssl: ?boolean, write_buffer_size: int, ssl_method: int}
* @return array{remote_socket: string|null, timeout: int, stream_context: resource, stream_context_options: array<string, mixed>, stream_context_param: array<string, mixed>, stream_flags: ?int, ssl: ?boolean, write_buffer_size: int, ssl_method: int}
*/
protected function configure(array $config = [])
{
Expand All @@ -154,6 +154,7 @@ protected function configure(array $config = [])
'timeout' => null,
'stream_context_options' => [],
'stream_context_param' => [],
'stream_flags' => 0,
'ssl' => null,
'write_buffer_size' => 8192,
'ssl_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
Expand All @@ -165,6 +166,7 @@ protected function configure(array $config = [])

$resolver->setAllowedTypes('stream_context_options', 'array');
$resolver->setAllowedTypes('stream_context_param', 'array');
$resolver->setAllowedTypes('stream_flags', 'int');
$resolver->setAllowedTypes('stream_context', 'resource');
$resolver->setAllowedTypes('ssl', ['bool', 'null']);

Expand Down