2009-09-16 1 views
0

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(); 
?> 
+0

Windows PC에서 실행해야합니다. 그래서 schtaks 더 좋을까요? –

답변

0

PHP 스크립트를 구성 제한 시간이있다. 일반적으로 이것은 php.ini 파일에서 기본값으로 30 초로 설정되고 max_execution_time 설정으로 구성 할 수 있습니다. 이 제한을 제거하려면 set_time_limit(0) (set_time_limit() 참조)로 전화하는 것이 좋습니다.

그 외에는 스크립트가 시간 초과되는 특별한 이유가 없습니다. 처리를 용이하게하기 위해 file_get_contents() 전화에서 @을 제거하고 handle any triggered errors yourself을 제거 할 수 있습니다. 문제가 발생하면 문제를 보게 될 가능성이 매우 높습니다.

+0

PHP 파일을 스크립트로 실행할 수있는 것 같습니다. ie 웹 서버없이. 이 모드에서 PHP는 제한 시간을 자동으로 0으로 설정합니다. http://www.php.net/manual/en/features.commandline.php –