When I do this.
$client = new GuzzleHttp\Client(['base_uri' => 'http://httpbin.org']);
$client->request('GET', '/get', ['debug' => true]);
I get
Warning: curl_setopt_array(): cannot represent a stream of type Output as a STDIO FILE* in C:\xampp\htdocs\xxx\lib\guzzle\GuzzleHttp\Handler\CurlFactory.php on line 57
Warning: curl_setopt_array(): cannot represent a stream of type Output as a STDIO FILE* in C:\xampp\htdocs\xxx\lib\guzzle\GuzzleHttp\Handler\CurlFactory.php on line 57
Warning: curl_setopt_array(): cannot represent a stream of type Output as a STDIO FILE* in C:\xampp\htdocs\xxx\lib\guzzle\GuzzleHttp\Handler\CurlFactory.php on line 57
Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 0: The cURL request was retried 3 times and did not succeed. The most likely reason for the failure is that cURL was unable to rewind the body of the request and subsequent retries resulted in the same error. Turn on the debug option to see what went wrong. See https://bugs.php.net/bug.php?id=47204 for more information. (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in C:\xampp\htdocs\xxx\lib\guzzle\GuzzleHttp\Handler\CurlFactory.php:187 Stack trace: #0 C:\xampp\htdocs\xxx\lib\guzzle\GuzzleHttp\Handler\CurlFactory.php(485): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 C:\xampp\htdocs\xxx\lib\guzzle\GuzzleHttp\Handler\CurlFactory.php(147): GuzzleHttp\Handler\CurlFactory::retryFailedRewind(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Array) #2 C:\xampp\htdocs\xxx\lib\guzzle\GuzzleHttp\Handler\CurlFactor in C:\xampp\htdocs\xxx\lib\guzzle\GuzzleHttp\Handler\CurlFactory.php on line 187
It looks like Guzzle was not able to open a stream for curl to write to. The stream provided to curl has to be a STDIO stream, so custom streams are not supported. The logic for determining the default stream is in debug_resource: https://github.com/guzzle/guzzle/blob/master/src/functions.php#L85.
Has STDOUT been remapped to some custom stream in your script?
Does changing this line to use "rw" instead of "w" fix the issue?
https://github.com/guzzle/guzzle/blob/master/src/functions.php#L92
Hi mtdowling, I'm having the same problem and changing w to rw on that line didn't fix the problem.
Some specs:
Changing php://output to php://memory only changes the "Output" debug string to "MEMORY".
The thing is, doing a GET to Google.com and getting the Body goes correctly as expected (minus the charset, of course), or even a GET on a GET itself (http://client.dev/test/) so it seems that could be a PHP Configuration thing. I had the same problem with Apache.
Does that means that PHP gets confused as it can't work with the same request in the same server? Like php://output couldn't be used two times in a single instance or something.
My configuration in NGINX is based on virtual hosts. http://game.dev/test -> http://client.dev/test. It _should_ work with no problem as both are on localhost, but be my guest why this doesn't work, and we get that error.
My hunch was right, it seems. Guzzle won't work at all if the same instance of PHP is used to send the Request from Guzzle, and to respond that request. Basically, one instance of PHP on the same server is a no go.
How to (temporally) fix this? I just elevated a second PHP-CGI listening in port :667, and in NGINX I used the fastcgi_pass 127.0.0.1:667; for the http://game.dev/test. Guzzle worked successfully with results.
In other words, a PHP Instance for Guzzle and another PHP Instance to receive must be done.
May be from Guzzle this can be "fixed", but I doubt it.
Just a heads up for those who are running the same PHP instance for Request and Responses.
@DarkGhostHunter solution isn't working for me, the issue comes and goes from time to time, it was working fine but fails today. If you can please provide any help.
OS: Win 7
Server: Apache
PHP: 7.0.10
@JefferyHus I think it won't work with Apache it self, as it will run in the same PHP thread or instance. Hence, why I migrated from Apache (PHP TS) to NGINX (PHP-FPM).
@DarkGhostHunter Well I have just tested the script on an Nginx 1.10.0 server the same issue remains.
If it helps at all, I'm encountering the same issue here without the use of Guzzle, just making a vanilla curl request. I've tried changing the mode parameter on the fopen function as suggested above and also ensured it's invoked only once in a script in case it didn't like being called multiple times, but with no luck.
Just my two pence here, thanks.
Setup: Win 10 with XAMPP, Apache/2.4.25, PHP/5.6.30
try, php://temp and w+
@akmua I tried your suggestion and it worked like a charm. Thank you.
So in my case I just set debug to false...
same on windows 10, php7.2. Headers are broken
When running on the PHP devserver, php 7.2.6 and windows 10, i was able to get it to work with
'debug' => fopen('php://stderr', 'w'),
This issue was automatically classified as stale because it lacks information or cannot be reproduced.
If you think the issue is still valid and/or misclassified, please comment on the issue thread
and provide additional information (if possible).
Also, since the time maintainers can spend on the project is limited, please provide
a possible solution if possible, especially if it involves a platform that we cannot
test ourselves (Windows, very old/specific PHP versions, etc).
Issues marked as stale with no further activity will be marked as rotten
at some point and will automatically be closed within 14 days.
We do this so that we can focus on high priority issues. Thank you for your understanding.
When running on the PHP devserver, php 7.2.6 and windows 10, i was able to get it to work with
'debug' => fopen('php://stderr', 'w'),
This helped. I had the same issue on Windows 10, XAMPP with PHP 7.
Thank you eteeselink and subzerofx
Your comment helped me on this problem on windows10, php 7 and apache
changing statement in function debug_resource($value = null)
from:
'debug' => fopen('php://output', 'w'),
to:
'debug' => fopen('php://stderr', 'w'),
i resolve it by my incorrect Client constructor;
change
$client = new Client(array('curl' => array('CURLOPT_SSL_VERIFYPEER' => false,),));
to
$client = new Client([
'curl' => [CURLOPT_SSL_VERIFYPEER => false]
]);
and bingo
Hey guys!
Is this issue resolved then?
i get this problem when debug = true or when i set my curl options manually to debugging
on console it works, on web requests it doesn't
hope you will get the bug
Setting debug to false worked for me too.
For anyone working with multiple Laravel sites locally, run php artisan config:cache on both sites might help
Src: https://github.com/laravel/framework/issues/21533#issuecomment-334352170
When running on the PHP devserver, php 7.2.6 and windows 10, i was able to get it to work with
'debug' => fopen('php://stderr', 'w'),
Thanks this fix works for me
Most helpful comment
When running on the PHP devserver, php 7.2.6 and windows 10, i was able to get it to work with