您好,欢迎访问一九零五行业门户网

一下,下面这一段代码有没有办法优化一下性能

求助一下,下面这一段代码有没有办法优化一下性能
是这样的,我采集一点彩票开奖数据,
写了正则匹配,以经匹配出来了正确的结果数组($result)
但是呢,速度有一点慢,所以想请高手看看,有没有什么办法优化一下速度。
代码入下:
php code$str = file_get_contents('http://baidu.lehecai.com/lottery/draw/?agentid=5555');preg_match('/
(.*)/isu', $str, $strs);preg_match_all('/(|
]*>)(.*)/isu', $strs[0] , $output );foreach($output[2] as $value){ preg_match_all('/(| ]*>)(.*)/isu',$value ,$va); $result[] = $va[2];}for($i = 2, $size =count($result); $i ]* href=([^]*)[^>]*>(.*)/isu', $result[$i][0], $href); preg_match_all('/(]*>|]*>)(.*)(|)/isu', $result[$i][3], $matches); $result[$i][0] = http://baidu.lehecai.com/.$href[1][0]; $result[$i][3] = $matches[2];}//preg_match_all('/]*>(.*)/isu', $result[3][3][3], $matches); //$result[3][3][3] = preg_replace(/[\s]+/si,,$matches[1][0]);$result[3][3][3] = preg_replace(/[\s]+/si,,$result[3][3][3]);$result[3][3][3] = preg_replace(/\(.*\)/si,,$result[3][3][3]);//echo ; print_r($result);exit();/* * $result 说明 $result[$i][3] 为号码数 ; $result[$i][0] 为连接 ; $result[$i][1] 为开奖期数 ; * $i的说明如下表 : * 2:双色球 * 3:福彩3d * 4:七乐彩 * 5:华东15选5 * 6:东方6+1 * 8:大乐透 * 9:排列三 * 10:排列五 * 11:七星彩 * 12:22选5 * 13:14场胜负彩 * 14:任选9场 * 15:4场进球彩 * 16:6场半全场 * */
------解决方案--------------------
没法优化了。放到服务器上就快了
------解决方案--------------------
估计是采集耽误时间。你可以把后面正则部分注释掉试试。
当然ajax请求服务器也是需要时间来缓存的。
------解决方案--------------------
换 curl看看会不会好点,不过我猜应该不会有太大的区别.这不但跟你自身的网络cpu的处理能力还跟对方的网站相应速度有关联
------解决方案--------------------
缓存!
开奖又不是实时的
就打算天天开奖,也不可能,每分钟就开奖一次
其它类似信息

推荐信息