Kan vara värt att ta en titt på Guzzle (
http://guzzlephp.org/) om man vill använde detta i verkligheten.
Features
Supports GET, HEAD, POST, DELETE, PUT, PATCH, OPTIONS, and any other custom HTTP method
Allows full access to request and response headers
Persistent connections are implicitly managed by Guzzle, resulting in huge performance benefits
Send requests in parallel
Cookie sessions can be maintained between requests using the CookiePlugin
Allows custom entity bodies, including sending data from a PHP stream and downloading data to a PHP stream
Responses can be cached and served from cache using the caching forward proxy plugin
Failed requests can be retried using truncated exponential backoff with custom retry policies
Entity bodies can be validated automatically using Content-MD5 headers and the MD5 hash validator plugin
All data sent over the wire can be logged using the LogPlugin
Subject/Observer signal slot system for unobtrusively modifying request behavior
Supports all of the features of libcurl including authentication, compression, redirects, SSL, proxies, etc
Web service client framework for building future-proof interfaces to web services
Includes a service description DSL for quickly building webservice clients
Full support for URI templates
Advanced batching functionality to efficiently send requests or commands in parallel with customizable batch sizes and transfer strategies
Använder det flitigt när jag utvecklar diverse API'er- på senaste tiden har även Drupal 8 och Amazon SDK gått över till Guzzle, Fabian Potenciers Goutte bygger även den på Guzzle.
Varning: Lätt att bli bortskämd! ^^