Skip to content


Subversion checkout URL

You can clone with
Download ZIP
super simple (aka not fancy) wrapper over socket stuff for http connections
Tree: fd412d5dfc

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


This is just a simple wrapper over PHP's socket functions to make http requests a bit easier.

The class is both reusable and supports Keep-Alive. There's actually a decorator
class (SimpleHttp_KeepAlive) to make using Keep-Alive connections a bit easier.

When using normal (Connection: close not Keep-alive) connections the class will 
re-connect if you try to use it for another request. When using Keep-Alive the class
will just keep on using the same connection.

Anywho... this is a work in progress & was mostly intended for a couchdb library
i was/am gonna write but it mostly seems to be working so I thought some people
could get some use out of it.

Check out the examples in the examples folder & feel free to report or fix bugs.


----------------------- Quick examples -----------------------


 * Connection: close example (aka "normal")

$socket = new SimpleHttp(''); // we wanna connect to google
$socket->setConnectTimeout(1);              // set connection timeout to 1 second
$socket->setStreamTimeout(1, 20);           // set read/write timeout to 1 second + 20ms
$socket->get('/');                          // perform an HTTP GET on the path "/"

print_r($socket->getResponseHeaders());     // take a look at the response headers
print_r($socket->getResponseStatus());      // check out the HTTP response status
print_r($socket->getResponseBody());        // output the body of the HTTP response
print_r($socket->getRawResponse());         // the raw server response... headers & body not parsed out

 * Connection: Keep-Alive example
 * You'll need to find a server that does Connection: keep-alive
 * I created a vhost on my local box. see etc/ folder for a sample conf file

$socket = new SimpleHttp_KeepAlive('couchdb.local');    

echo "First request\n\n";

echo "Second request on same connection\n\n";

// more examples in the examples folder

Something went wrong with that request. Please try again.