Deprecated Methods in Pecl_Http

I’m a big fan of pecl_http, which I use quite often as I work so regularly with APIs and on systems where I can get it installed, it’s much nicer than PHP’s curl extension. Recently though I’ve been often seeing output which reads:

Function HttpRequest::addRawPostData() is deprecated

It isn’t obvious from the PHP manual page what I ought to do instead, however further inspection shows that it is recommended to use setBody() instead. This can be used in exactly the same way, and my code seems to work perfectly well with this substitution. If you have any more information about this change, leave me a comment – I’d be interested to hear it.

5 thoughts on “Deprecated Methods in Pecl_Http

  1. Well, I’m not a frequent user of the package, but when it comes to semantics, the choice for setBody as opposed to addRawPostData is obvious: a HTTP body isn’t limited to a POST request, also PUT requests may contain a body, so the method was incorrectly named. Perhaps that’s the reason they have renamed it?

    PHP has a long standing tradition of using “odd” names for stuff like this anyway: consider the $_GET superglobal, which isn’t restricted to GET requests at all, and $_POST is readable when using a PUT request too. Better names would’ve been $_QUERY and $_BODY, but hey, that’s just nitpicking ;)

  2. The HTTP extension is nice in theory, but it’s seldomly installed on shared hosting. So, does anyone know of a pure PHP reimplementation of it (as fallback)? It’s also not exactly necessary to have it implemented in C anyway.

  3. berry__: agreed, I didn’t really see the “odd” naming, because I’m so used to slightly misleading naming. I am actually impressed they are changing it!

    mario: as far as I am aware, you can do everything with the cURL extension in PHP, it’s just clunkier to work with. I am pretty lucky that I control my own platforms!

  4. Mario, Zend Framework provides Zend_Http_Client, which knows a great many adapters. That means you can use the same consistent interface on each and every host, while actually using cURL or PECL’s HTTP extension, or possibly even a pure sockets-based implementation, and you don’t have to change a line of code. Nice, huh?

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.