2017-10-09 27 views
0

我有一個使用Yii框架編寫的php應用程序。Yii php應用程序在30秒後處理csv文件

控制器實際上給我一個問題,獲取一個csv文件,打開它來讀取內容併爲每個csv文件行添加/更新數據庫記錄。

public function actionGetCSVArticleData(){ 
    try { 
     $file = fopen("C:\\wamp\\www\\ps\\articoli.csv","r"); 
     $result =""; 
     $i=0; 
     while (($data = fgetcsv($file, 1000, ";")) !== FALSE) 
     { 
      $result[$i++]= $data; 
     } 

     for($j=1;$j<count($result);$j++){ 
      for($k=0;$k<count($result[$j]);$k++){ 
       $tempData = $result[$j]; 
       $articleMgmt = new ArticleMgmt(); 

       if(isset($tempData[0]) && isset($tempData[3])) { 
        $articleMgmt->code=trim($tempData[0]); 
        $articleMgmt->customer_code=trim($tempData[3]); 
       } else { 
        $articleMgmt->code=null; 
       } 

       if($articleMgmt->code!=null){ 
        $tCode = $this->isArticleExist($articleMgmt->code, $articleMgmt->customer_code); 

        if($tCode !=-1){ 
         $updateArticle = ArticleMgmt::model()->findByPk($tCode); 
         $this->updateArticle($updateArticle,$tempData); 
        }else{ 
         $this->updateArticle($articleMgmt,$tempData); 
        } 
       } 
      } 
     } 
     fclose($file); 

     $count = ArticleMgmt::model()->count(); 
     $articleData = ArticleMgmt::model()->findAll(); 
     $result = array('data' => $articleData, 'total' => $count); 

     echo CJSON::encode($result); 
    } catch(Exception $e){ 
     echo CJSON::encode(array("success" => false, 'message' => $e->getMessage())); 
    } 
} 

問題是,30秒後控制器方法的調用被取消,它不處理整個文件,但只處理第一部分。想想看,我有一個文件大約40.000行和它打破後約7800 chrome consolle error 奇怪的是,我已經檢查和修改php.ini中沒有任何結果:

max_execution_time = 600 
max_input_time = 120 
memory_limit = 256 Mb 

enter image description here 我不不明白我錯在哪裏。

回答

0

確定
你編輯正確的php.ini,
和你
max_execution_time=600
你有沒有改變後重新啓動的Apache的phpinfo?

+0

是;我在每個php.ini更改之後重新啓動apache,並且還使用phpinfo()進行了檢查,並且我目前看到更改後的值。 您可以在我編輯的問題中看到捕獲 – agodoo

+0

您可能在apache錯誤日誌中檢查過嗎? – Rafael

+0

我知道這可能是愚蠢的,但你有沒有嘗試在php代碼 'set_time_limit(120);' – Rafael