|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67802 Streams API cannot return error body/content
Submitted: 2014-08-07 14:51 UTC Modified: 2014-08-07 15:12 UTC
From: chad at getfidelis dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.5.15 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: chad at getfidelis dot com
New email:
PHP Version: OS:


 [2014-08-07 14:51 UTC] chad at getfidelis dot com
I have been unable to find any way to access body content using the HTTP stream wrapper, if the response contained an HTTP error code.

I'm trying to contact a REST API that returns useful error data in the body (pinpointing, for instance, _which parameter_ is incorrect and what the proper range or format for its value is) with error codes 400 and up.  When this error code is returned, fopen() returns FALSE, and it's not possible to access the response.

$http_response_header contains the *headers* but not the body.  All of the stream functions require a resource, which fopen() clearly didn't return, and substituting a context passed to the fopen() call also fails (which I expected, but tried anyway.)  There does not seem to be any sort of stream_get_last_error() function, either.

I can pull this off with cURL of course, but the streams API is generally more convenient to use.

Test script:
# I can't give you my password for the API, so I'll use google...
$fp = fopen("", 'r');
print_r($http_response_header); # does not have body
print_r(array_keys($GLOBALS));  # no useful vars present
if ($fp)
        echo 'got a stream', PHP_EOL; # never runs


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-07 15:12 UTC]
-Status: Open +Status: Not a bug
 [2014-08-07 15:12 UTC]
You can set the ignore_errors context option to always retrieve the body, per
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 00:01:33 2024 UTC