Skip to content

Commit 4cb1436

Browse files
committed
Fix "Warning: curl_setopt(): cannot represent a stream of type MEMORY as a STDIO FILE*"
1 parent 5ac7f6f commit 4cb1436

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Curl/Curl.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,14 @@ protected function exec($_ch = null)
438438
$ch = $_ch === null ? $this : $_ch;
439439

440440
$response_headers_fh = fopen('php://memory', 'wb+');
441-
$ch->setOpt(CURLOPT_WRITEHEADER, $response_headers_fh);
441+
442+
// Fallback to storing data in a temporary file when storing data in
443+
// memory errors with "Warning: curl_setopt(): cannot represent a stream
444+
// of type MEMORY as a STDIO FILE*".
445+
if (!@$ch->setOpt(CURLOPT_WRITEHEADER, $response_headers_fh)) {
446+
$response_headers_fh = fopen('php://temp', 'wb+');
447+
$ch->setOpt(CURLOPT_WRITEHEADER, $response_headers_fh);
448+
}
442449

443450
if ($ch->multi_child) {
444451
$ch->raw_response = curl_multi_getcontent($ch->curl);

0 commit comments

Comments
 (0)