请考虑以下事项:我正在使用通过API下载的gzip压缩文件来实时呈现数据(constructTable)。首先,我检查文件是否已下载,然后是否完整(应该执行更彻底的检查,只是不知道如何)。如果一切正常,它应该读取文件并将其转换为数组 - 我将返回到递归函数,然后将其返回到我的constructTable函数。但是数组不会从checkReport函数返回到constructTable。我做错了什么?
function fileToArray($filePath){
$file = fopen($filePath,'rb');
$gzipcsv = fread($file, filesize($filePath));
fclose($file);
$ungzipcsv = gzdecode($gzipcsv);
return parse_csv($ungzipcsv);
}
function checkReport($filePath,$queryStr,$status=''){
if($status!='ok'){
if(!file_exists($filePath)){
if($status!='creating_report'){
DownloadReport($_SESSION['currentUser'],$filePath,$queryStr);
$status='creating_report';
} else {
usleep(100000);
$status='downloading_report';
}
} else {
if(filesize($filePath)!=0){
$fs = filesize($filePath);
usleep(100000);
clearstatcache(TRUE, $filePath);
if($fs==filesize($filePath)){
$status='ok';
} else {
$status='downloading_report';
}
} else {
$status='zero_filesize';
}
}
checkReport($filePath,$queryStr,$status);
} else {
return fileToArray($filePath);
}
}
function constructTable($user, $fields, $dataType, $reportName, $conditionItem, $conditionId, $dateRange) {
$filePath = dirname(dirname(__FILE__)) . '/csv/'.$GLOBALS['customer'].'__'.$dataType.'__'.$reportName.'.csv.gz';
$queryStr = 'SELECT '.implode(',',$fields);
$queryStr .= ' FROM '.$reportName;
$queryStr .= '';
if($conditionId!='') $queryStr .= ' WHERE '.$conditionItem.' = '.$conditionId;
$queryStr .= ' DURING '.$dateRange;
$csv_array = NULL;
$i = 0;
while(!$csv_array){
if($i++>2){
break;
}
$csv_array = checkReport($filePath,$queryStr);
var_dump(checkReport($filePath,$queryStr));
}