PHP 从 csv 下载文件,超时


PHP download files from csv, timing out?

>我在下面有一个php文件,它查看文件"index.csv",其中包含两个标头,file|path

下面的文件将请求的 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_set("memory_limit","240M")//set your preferred count