My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Links

REST client library with the possibility of execute threaded REST calls in PHP thanks to curl's 'multi' functions.

require_once('http.php');

// multiple call in one host
$out = Http::connect('localhost', 8082)
    ->silentMode()
    ->get('/tests/gam_http/sleep.php', array('sleep' => 3))
    ->post('/tests/gam_http/sleep.php', array('sleep' => 2))
    ->get('/tests/gam_http/sleep.php', array('sleep' => 2))
    ->post('/tests/gam_http/sleep.php', array('sleep' => 2))
    ->get('/tests/gam_http/sleep.php', array('sleep' => 2))
    ->post('/tests/gam_http/sleep.php', array('sleep' => 2))
    ->get('/tests/gam_http/sleep.php', array('sleep' => 1))
    ->run();
print_r($out);

// multiple call in different hosts
$out = Http::multiConnect()
    ->add(Http::connect('localhost', 8082)->get('/tests/gam_http/sleep.php', array('sleep' => 1)))
    ->add(Http::connect('localhost', 8082)->get('/tests/gam_http/sleep.php', array('sleep' => 2)))
    ->run();
print_r($out);

//single calls
echo Http::connect('localhost', 8082)
    ->doGet('/tests/gam_http/sleep.php', array('sleep' => 3));

echo Http::connect('localhost', 8082)
    ->doPost('/tests/gam_http/sleep.php', array('sleep' => 2));

echo Http::connect('localhost', 8082)
    ->doDelete('/tests/gam_http/sleep.php', array('sleep' => 1));
echo '<p>This page was created in ' . Timer::end() . ' seconds.</p>';

// exceptions
try {
   echo Http::connect('localhost', 8082)
        ->doGet('/tests/gam_http/sleep.php', array('sleep' => 3));
} catch (Http_Exception $e) {
    switch ($e) {
        case Http_Exception::INTERNAL_ERROR:
            echo "Internal Error";
            break;
    }
}
Powered by Google Project Hosting