Categories php solar

HTTP streams are usable in 5.3.0

en_US 23 Jul 2008 @ 23:35:31 No comments

While working with my Solarified wrapper for Amazon's S3, I found out that prior to version 5.3.0, HTTP streams in PHP are almost unusable.

The problem comes when you make an HTTP request and the server responds with an error status code. What happens is that prior to version 5.3 the HTTP stream context considers an error status code a real PHP-level error. Now, instead of returning the response body, it returns false from functions like fread() and file_get_contents(). This is a huge problem with a service like S3 where you often get an error response with a body explaining what was wrong.

Fortunately, PHP 5.3.0 introduces a new HTTP stream context option ignore_errors which, once set on, will treat error statuses the same way as non-error statuses. I think this should definitely be the default behaviour.

I ended up using the excellent pecl_http extension for my HTTP requests. The result is a new HTTP request adapter for Solar: Lux_Http_Request_Adapter_Http (stupid name I know, will change that :-).

UPDATE: It's fread() and not fopen() that returns data from a stream. Fixed that.

Comments

No comments

Add your comment

Will not be published. Finds your Gravatar.
Style guide
Your comment will be added immediately. Please be nice.
Don't fill this if you think you're human