我正在为客户端开发基于Web的RESTful API。除了一个请求之外,一切都很好,我需要为每一行请求Foursquare API。优化性能:许多CURL请求
此请求的URL是:3210。
目前到该URL的请求的响应是:
{
"response": {
"user": {
... some user info ...
"times": [
{
"id": "8",
"venue_fq_id": "4b81eb25f964a52000c430e3",
"user_id": "1",
"wait_length": "4468",
"created_at": "2012-06-09 21:45:43"
},
{
"id": "9",
"venue_fq_id": "4aad285af964a520c05e20e3",
"user_id": "1",
"wait_length": "8512",
"created_at": "2012-06-09 21:45:43"
},
{
"id": "10",
"venue_fq_id": "42377700f964a52024201fe3",
"user_id": "1",
"wait_length": "29155",
"created_at": "2012-06-09 21:45:44"
},
{
"id": "11",
"venue_fq_id": "45c88764f964a5206e421fe3",
"user_id": "1",
"wait_length": "33841",
"created_at": "2012-06-09 21:45:44"
},
{
"id": "12",
"venue_fq_id": "430d0a00f964a5203e271fe3",
"user_id": "1",
"wait_length": "81739",
"created_at": "2012-06-09 21:45:44"
}
]
}
},
"stat": "ok"
}
然而,venue_fq_id
response.user.times
所述阵列中被返回相对于所述四方API的场所。我试着对每行的Foursquare API运行curl请求,但是性能非常慢。请您举例说明我可以如何加快性能,同时检索我每次访问时都要求的F/Q API的相同信息?
这里是我的代码:
$query = $this->db->query("SELECT * FROM `wait_times` WHERE `user_id` = ?", array($email_address));
$wait_times = $query->result();
foreach ($wait_times as $wait_time) {
$wait_time->venue = $this->venue_info($wait_time->venue_fq_id);
}
function venue_info($fq_id) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.foursquare.com/v2/venues/4b522afaf964a5200b6d27e3");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch));
curl_close($ch);
return $response['response']['venue'];
}
这需要在不登录的情况下完成。 – 2012-08-12 19:36:28