15 Jan 2014 - Münster (by Evert)

sabre/http 2.0 released

Last week we released a new open source library, sabre/http.

This library makes working with HTTP-related features in PHP a lot easier. The package was actually embedded into sabre/dav for nearly 5 years, but this is the first time it's released stand-alone.

Some technical details

As a PHP developer, you often touch upon HTTP. Usually, because your PHP application is running on a HTTP server.

PHP provides several mechanisms to access information about the PHP request, specifically: $_GET, $_POST, $_SERVER and php://input, and several mechanisms to influence the response, such as echo, header and php://output.

All of these are 'global'. Meaning that there is only one of them per PHP request, which makes sense, as a PHP script tends to only live for the lifetime of a single HTTP request.

Purely depending on these global mechanisms can cause issues though. If you'd like to unittest these you will be modifying globals (generally not a recommended practice), or in a situation where you want to do a sub-request in a request (not entirely uncommon in many frameworks), the sub-request may now modify the state of the top-level request.

If you're already deep into OOP, sabre/http provides a OOP wrapper around the request and response. This can potentially make your application more robust, but also provides a much more elegant way of dealing with requests and responses in php.

The package also provides a rudimentary client, that actually uses the exact same Request and Response objects.

The client wraps around Curl, and allows you to make HTTP requests asynchronously.

A side-effect of using the same request and response objects for both the server and the client, is that it actually becomes really easy to create a simple reverse proxy.


The full documentation can be found on the github project page.

We hope you like it as much as we do. If you're using this new package in any way, we would love to hear from you.

About Evert

Evert loves to write code, and everything related at fruux. He suffers from a severe case of semantic satiation of everything calendar related, and has an unrequited love for ice tea. Follow him on Twitter.

fruux is a free service that looks after your contacts, calendars and tasks so you don't have to. It makes sure that they are always in sync, no matter which device or operating system you're using. If you've not tried it yet, then why not check us out and let us know what you think! And if you're already using fruux, then we'd love to hear your thoughts and comments. You can also suggest a feature for any upcoming releases or tweet us: @fruux.