当我尝试使用PHPExcel库从上传文件夹中读取上传的excel文件时,可能会导致错误,我无法找到原因。根据Nginx日志,有#34;连接由同行重置"错误如下:
[error] 111#111: *124 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.17.0.1,
直到行$objPHPExcel = $objReader->load( $file_name );
一切正常但在这一行上,文件无法执行,除此之外,catch块中没有任何异常。
由于此问题,Nginx在浏览器中出现502 Bad Gateway
错误。
public function load_excel( $file_name )
{
try {
/** Identify the type of $inputFileName **/
$inputFileType = \PHPExcel_IOFactory::identify( $file_name );
/** Create a new Reader of the type that has been identified **/
$objReader = \PHPExcel_IOFactory::createReader( $inputFileType );
/** Advise the Reader that we only want to load cell data **/
$objReader->setReadDataOnly( true );
/** Load $inputFileName to a PHPExcel Object **/
$objPHPExcel = $objReader->load( $file_name );
} catch(\PHPExcel_Reader_Exception $e) {
error_log($e->getMessage());
return false;
}
return $objPHPExcel;
}