Skip to content

Commit f6a1930

Browse files
authored
Fix #250: Fixed TypeError: stream_get_contents(): Argument #1 ($stream) must be of type resource, bool given in case PHP error reporting is turned off
1 parent 0b4de01 commit f6a1930

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
steps:
1919
- name: Checkout
20-
uses: actions/checkout@v2
20+
uses: actions/checkout@v5
2121
- name: Install PHP
2222
uses: shivammathur/setup-php@v2
2323
with:
@@ -26,7 +26,7 @@ jobs:
2626
id: composer-cache
2727
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
2828
- name: Cache composer dependencies
29-
uses: actions/cache@v1
29+
uses: actions/cache@v4
3030
with:
3131
path: ${{ steps.composer-cache.outputs.dir }}
3232
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Yii Framework 2 HTTP client extension Change Log
44
2.0.17 under development
55
------------------------
66

7-
- no changes in this release.
7+
- Bug #250: Fixed `TypeError: stream_get_contents(): Argument #1 ($stream) must be of type resource, bool given` in case PHP error reporting is turned off (shaperman)
88

99

1010
2.0.16 February 13, 2025

src/StreamTransport.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,18 @@ public function send($request)
5959
try {
6060
$context = stream_context_create($contextOptions);
6161
$stream = fopen($url, 'rb', false, $context);
62+
if (false === $stream) {
63+
$error = error_get_last();
64+
throw new Exception(sprintf('Error while fopen(%s): %s', $url, isset($error['message']) ? $error['message'] : 'Unknown error'));
65+
}
6266
$responseContent = stream_get_contents($stream);
6367
// see https://php.net/manual/en/reserved.variables.httpresponseheader.php
6468
$responseHeaders = (array)$http_response_header;
6569
fclose($stream);
6670
} catch (\Exception $e) {
71+
if (isset($stream) && is_resource($stream)) {
72+
fclose($stream);
73+
}
6774
Yii::endProfile($token, __METHOD__);
6875
throw new Exception($e->getMessage(), $e->getCode(), $e);
6976
}

0 commit comments

Comments
 (0)