mysql - thinkphp3.2 csv批量導(dǎo)入上萬(wàn)條數(shù)據(jù)時(shí)報(bào)錯(cuò)超時(shí),請(qǐng)問(wèn)有什么好的辦法處理?
問(wèn)題描述
$filename = $_FILES[’data’][’tmp_name’]; $handle = fopen($filename, ’r’); $result = input_csv($handle); //解析csv $length = count($result); for ($i = 0; $i < $length; $i++) { $ip = $result[$i][0]; $port = $result[$i][1]; //... $data = array('ip' => $ip,'port' => $port,//... ); $count = $Property->where($where)->find(); if($count){$query = $Property->where($where)->save($data); }else{$query = $Property->add($data); }}fclose($result); $this->success(’導(dǎo)入成功!’);exit();
上傳CSV文件,執(zhí)行后就報(bào)錯(cuò)了,求大神支招ps:必須要判定IP+端口唯一,存在則覆蓋,不存在則添加。
問(wèn)題解答
回答1:兩種,一種是設(shè)置超時(shí)時(shí)間限制,還有一種就是把它轉(zhuǎn)化成sql最后拿到數(shù)據(jù)庫(kù)執(zhí)行,我推薦第二種,這種性能好
