From 4cb1436983bd7c73096bdcd0461b9a3bf4d12998 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Tue, 30 Dec 2014 17:04:10 -0800 Subject: [PATCH] Fix "Warning: curl_setopt(): cannot represent a stream of type MEMORY as a STDIO FILE*" --- src/Curl/Curl.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 4d5bb24..399d7b1 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -438,7 +438,14 @@ class Curl $ch = $_ch === null ? $this : $_ch; $response_headers_fh = fopen('php://memory', 'wb+'); - $ch->setOpt(CURLOPT_WRITEHEADER, $response_headers_fh); + + // Fallback to storing data in a temporary file when storing data in + // memory errors with "Warning: curl_setopt(): cannot represent a stream + // of type MEMORY as a STDIO FILE*". + if (!@$ch->setOpt(CURLOPT_WRITEHEADER, $response_headers_fh)) { + $response_headers_fh = fopen('php://temp', 'wb+'); + $ch->setOpt(CURLOPT_WRITEHEADER, $response_headers_fh); + } if ($ch->multi_child) { $ch->raw_response = curl_multi_getcontent($ch->curl);