文章詳情頁
mysql - thinkphp3.2 csv批量導入上萬條數據時報錯超時,請問有什么好的辦法處理?
瀏覽:62日期:2022-06-12 09:40:12
問題描述
$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(’導入成功!’);exit();
上傳CSV文件,執行后就報錯了,求大神支招ps:必須要判定IP+端口唯一,存在則覆蓋,不存在則添加。
問題解答
回答1:兩種,一種是設置超時時間限制,還有一種就是把它轉化成sql最后拿到數據庫執行,我推薦第二種,這種性能好
排行榜
![css3 - [CSS] 動畫效果 3D翻轉bug](http://www.cgvv.com.cn/attached/image/news/202304/110831f073.png)