phatduckk / Duckk_SimpleHTTP
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
Arin Sarkissian (author)
Sat May 16 13:32:56 -0700 2009
commit fd412d5dfc42e915157f081dccd049be32990f97
tree 0dfcbfcbf4e32552642256928b339594e949b6cd
parent e0f81ae75b27000a0a831f1279e33e0c3306fd5b
tree 0dfcbfcbf4e32552642256928b339594e949b6cd
parent e0f81ae75b27000a0a831f1279e33e0c3306fd5b
README
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.
-Arin
----------------------- Quick examples -----------------------
<?php
/*
* Connection: close example (aka "normal")
*/
$socket = new SimpleHttp('www.google.com'); // 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";
$socket->get('/');
print_r($socket->getResponseBody());
echo "Second request on same connection\n\n";
$socket->get('/_all_dbs');
print_r($socket->getResponseBody());
$socket->close();
// more examples in the examples folder
?>
