首頁  >  問答  >  主體

mysql - thinkphp3.2 csv批次匯入上萬條資料報錯逾時,請問有什麼好的辦法處理?

$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 端口唯一,存在則覆蓋,不存在則添加。

#
大家讲道理大家讲道理2703 天前673

全部回覆(1)我來回復

  • 仅有的幸福

    仅有的幸福2017-05-25 15:10:12

    兩種,一種是設定超時時間限制,還有一種就是把它轉換成sql最後拿到資料庫執行,我推薦第二種,這種效能好

    回覆
    0
  • 取消回覆