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);
}
}
連接是否穩定?你的'php.ini'文件中的'max_execution_time'設置是什麼? – ferdynator
@ byf-ferdy Max_execution_time = 64400 – user2231688
所以你可能會用完時間。您可以使用cronjob來分割下載文件 – ferdynator