0

以下にphpファイルがあります。これは、ファイル「index.csv」を調べます。このファイルには、file | pathという2つのヘッダーが含まれています。

以下のファイルは、要求された xml ファイルをフォルダー「productxml」にダウンロードします。

ただし、上記のcsvファイルで300,000を超えるファイルが参照されている698個のファイルしかダウンロードしていないため、タイムアウトか何かのようです。

何が問題なのかについてのアイデアはありますか?

<?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);
    }
}
4

1 に答える 1