gpt4 book ai didi

codeigniter - PHP 函数 curl_exec() 减慢了我的脚本速度

转载 作者:行者123 更新时间:2023-12-04 06:44:50 27 4
gpt4 key购买 nike

我在 CodeIgniter 中使用以下函数来获取我的最新推文:

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;

}

我用CI的Benchmark类看看为什么网站响应时间这么长,发现那一行
 $src = curl_exec($c);

执行时间超过 5 秒。谁能告诉我为什么会这样?

最佳答案

关于codeigniter - PHP 函数 curl_exec() 减慢了我的脚本速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3862691/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com