I use the following function in CodeIgniter, to get my latest tweet:
function tweet($id) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/".$id.".xml?count=1");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
//Benchmark starts here
$src = curl_exec($c);
//Benchmark ends here
curl_close($c);
preg_match('/<text>(.*)<\/text>/', $src, $t);
$data['tweet'] = htmlentities($t[1]);
preg_match('/<created_at>(.*)<\/created_at>/', $src, $c);
$created = $c[1];
// explode $created so we can process it
$created_array = explode(' ',$created);
$time = $created_array[3];
$time_array = explode(':',$time);
$format = '%b/%d/%Y %H:%M';
$date_to_format = $created_array[1].'/'.$created_array[2].'/'.$created_array[5].' '.$time_array[0].':'.$time_array[1];
$date_time = strptime($date_to_format,$format);
$created_timestamp = mktime($date_time['tm_hour'], $date_time['tm_min'], 0, $date_time['tm_mon']+1, $date_time['tm_mday'], $date_time['tm_year']+1900);
$time_diff = time() - $created_timestamp;
$data['time'] = time_since($time_diff);
return $data;
}
I use the Benchmark class of CI to see why the website takes so long to respond, and I found that the line
$src = curl_exec($c);
takes more than 5 seconds to execute. Can anyone tell me why this is happening?