2013-10-19 106 views
0

我下面有一個php文件,它查找文件「index.csv」,其中包含兩個標題,文件|路徑PHP從csv下載文件,超時?

以下文件將請求的xml文件下載到文件夾「productxml」中。

但是,它似乎是超時或什麼的,因爲它只下載698個文件,其中上面的csv文件中引用了超過300,000個文件。

任何想法可能是什麼問題?

<?php 
    set_time_limit(0); 
$fileContent = file("index.csv"); // read the file to an array 
array_shift($fileContent); // remove the first line, the header, from the array 
foreach($fileContent as $line) { 
    $columns = str_getcsv($line, "|", '"'); 
    $url = $columns[1]; // as suposed previously the url is in the second column 
    $filename = $columns[0]; 
    downloadFile($url, $filename); 
} 

function downloadFile($url, $filename) { 
    $newfname = "../productxml/" . $filename ; 
    $file = fopen ($url, "rb"); 
    if ($file) { 
     $newf = fopen ($newfname, "wb"); 
     if ($newf) 
      while(!feof($file)) { 
       fwrite($newf, fread($file, 1024 * 8), 1024 * 8); 
      } 
    } 
    if ($file) { 
     fclose($file); 
    } 

    if ($newf) { 
     fclose($newf); 
    } 
} 
+0

連接是否穩定?你的'php.ini'文件中的'max_execution_time'設置是什麼? – ferdynator

+0

@ byf-ferdy Max_execution_time = 64400 – user2231688

+0

所以你可能會用完時間。您可以使用cronjob來分割下載文件 – ferdynator

回答

0

您可能內存不足。嘗試設置

<?php 
ini_set("memory_limit","240M")//set your preferred count 
+0

是否沒有辦法讓它以一次500塊的方式下載,一秒鐘的休眠以及停止的恢復,從而刷新內存等?謝謝你的幫助 – user2231688