Skip to content

Commit 46cabd6

Browse files
committed
Merge branch 'fixStreamGetContentsArgumentError'
2 parents 079de4f + d411a5e commit 46cabd6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/StreamTransport.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ public function send($request)
6161
$stream = fopen($url, 'rb', false, $context);
6262
if (false === $stream) {
6363
$error = error_get_last();
64-
throw new Exception(sprintf('Error while fopen(%s): %s', $url, $error['message'] ?? 'Unknown error'));
64+
throw new Exception(sprintf('Error while fopen(%s): %s', $url, isset($error['message']) ? $error['message'] : 'Unknown error'));
6565
}
6666
$responseContent = stream_get_contents($stream);
6767
// see https://php.net/manual/en/reserved.variables.httpresponseheader.php
6868
$responseHeaders = (array)$http_response_header;
6969
fclose($stream);
7070
} catch (\Exception $e) {
71+
if (is_resource($stream)) {
72+
fclose($stream);
73+
}
7174
Yii::endProfile($token, __METHOD__);
7275
throw new Exception($e->getMessage(), $e->getCode(), $e);
7376
}

0 commit comments

Comments
 (0)