http 웹 사이트에서 시간순으로 명명 된 체계로 저장된 CSV 파일이 많습니다. 나는 프로그래밍 방식으로 날짜 함수를 사용하여 각 파일 이름을 생성하고 file_get_
contents()를 사용하여 파일을 로컬로 작성하는 PHP 프로그램 (localhost에서 실행)을 작성했습니다.file_get_contents()를 사용하여 원격 서버에서 1Gb 이상의 파일을 합치면 시간 초과가 발생합니까?
제한된 기간 동안 테스트를 마쳤으며 파일을 가져올 수 있습니다 (각각 약 1.3M). 그러나 큰 기간 (예 : 평일마다 파일로 3 년) 동안 시간 초과가 발생합니까? 아니면 응답이 실제로 중지되지 않았기 때문에 시간 초과가 아닌가?
여기 참조 용 코드입니다 :
<?php
$start_date = '08SEP2009';
$check_date = $start_date;
$end_date = '14SEP2009';
function getNextDate() {
global $check_date;
$check_date = date("dMY", strtotime ("+1 day", strtotime($check_date))); //get next date
return $check_date;
}
function downloadFiles() {
$cur_date = getNextDate();
$url = "http://nse-india.com/content/historical/DERIVATIVES/YYYY/MMM/foDDMMMYYYYbhav.csv"; //this represents the naming scheme for the CSVs
while(strcasecmp($cur_date, $end_date)) {
$year = date("Y", strtotime($cur_date)); //get year (2004)
$month = strtoupper(date("M", strtotime($cur_date))); //get month (SEP)
$day = date("d", strtotime($cur_date)); //get day of month (09)
$filename = str_replace('DD', $day, str_replace('MMM', $month, str_replace('YYYY', $year, $url))); //construct file name for new date
$content = @file_get_contents($filename);
$localfile = array_reverse(explode("/", $filename)); //reverse array so that filename.csv comes as first element
$localfile = $localfile[0]; //filename to store locally
$handle = fopen($localfile, "w");
fwrite($handle, $content); //save file locally
fclose($handle);
}
}
downloadFiles();
?>
Windows PC에서 실행해야합니다. 그래서 schtaks 더 좋을까요? –