Bir http web sitesinde, ben adlandırma şemasını kronolojik saklanan CSV dosyaları yükler. Ben programlı tarih fonksiyonları kullanarak her dosya adı oluşturmak ve yerel dosyaları yazmak için () file_get_
içerikleri kullanmak için (localhost üzerinde çalışan) bir PHP programı yazdı.
Ben tarihleri sınırlı bir dizi test ve dosyaları (1.3M etrafında her) almak mümkün oluyorum. Ancak, üzerinde (haftanın her günü için bir dosya ile diyelim ki, 3 yıl) Büyük bir dönem, bu bir zaman aşımı neden olur? Yanıtı aslında durmuş değil çünkü Ya da bir zaman aşımı değil mi?
İşte başvuru için kod:
<?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();
?>