Calling restful web services efficiently I need to use this code to fetch data from web service and show them in a site properly but after I request for the webservice I am unable to load them fast. Site is loading very slow.

&lt;?php

$jRequestURLPrefix = 'http://demo.4ds.com/rema/1.1/';

$menu_json_url  = $jRequestURLPrefix."rules/origins/b2c.json";

$menu_data      = get_json_data($menu_json_url);

/* Function get_json_data definition */

function get_json_data($json_url, $return_array = true, $print_array = false, $curl = true )
{
    $jsonString = '';
    $data       = array();
    if (!$curl)
    {
        /*
         *  if !$curl, use "file_get_contents" method
         *  to get JSON encoded string
        */
        $jsonString = file_get_contents($json_url);

    }
    else
    {
        /*
         *  if $curl, use "curl" method
         *  to get JSON encoded string
        */

        // Initializing curl
        $ch = curl_init( $json_url );

        // Configuring curl options
        $options = array(
            CURLOPT_RETURNTRANSFER =&gt; true,
            CURLOPT_HTTPHEADER =&gt; array('Content-type: application/json') ,
        );

        // Setting curl options
        curl_setopt_array( $ch, $options );

        // Getting JSON encoded string
        $jsonString =  curl_exec($ch); 
    }


    // convert the JSON encoded string into a PHP variable(array)
    //if($return_array)
        $data = json_decode($jsonString, $return_array);

    // $print_array == true, print the array
    if($print_array)
    {
        echo '&lt;pre&gt;';
        print_r($data);
        echo '&lt;/pre&gt;';
    }

    return $data;

}

?&gt;


After using the above procedure I am getting the response very slow.
I think its the API, I've just benchmarked it using

$json = file_get_contents('http://demo.4ds.com/rema/1.1/rules/origins/b2c.json');
$data = json_decode($json);


I only ran 10 attempts but they seem to take between 1 and 5 seconds each.

php test.php  0.03s user 0.01s system 2% cpu 1.574 total
php test.php  0.03s user 0.01s system 1% cpu 3.303 total
php test.php  0.04s user 0.01s system 0% cpu 5.881 total
php test.php  0.04s user 0.01s system 2% cpu 1.646 total
php test.php  0.03s user 0.01s system 2% cpu 1.478 total
php test.php  0.03s user 0.01s system 2% cpu 1.516 total
php test.php  0.03s user 0.01s system 2% cpu 1.590 total
php test.php  0.04s user 0.01s system 1% cpu 3.659 total
php test.php  0.03s user 0.01s system 1% cpu 3.582 total
php test.php  0.03s user 0.01s system 2% cpu 1.526 total