我的脚本中有一个函数在运行PHPStorm时突然导致502 Bad Gateway错误。我之前从未使用类似的脚本。当我发表评论时,我根本没有任何错误。怎么可能?
脚本从一个excel获取信息并将其转换为另一个。
public static function WJ_JewelsToExcel($array, $fileName) {
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$rowCount = 2;
foreach ($array as $row) {
$sku = $row[0];
$gender = $row[1];
$jewelType = $row[2];
$jewelType2 = $row[3];
$metalType = $row[4];
$metalColor = $row[5];
$gemType = $row[6];
$gemColor = $row[7];
$description = $row[9];
$brand = $row[10];
$msrp = $row[11];
$price = $row[12];
$qty = $row[13];
$url = $row[14];
$name = $brand . ' ' . $sku;
$finalGender = "";
if ($gender == "Female") {
$finalGender = "Women's";
} elseif ($gender == "Male") {
$finalGender = "Men's";
} else {
$finalGender = "Child";
}
for($categoryRow = 0 ; $categoryRow < 2 ; $categoryRow++){
if($categoryRow == 0){
$objPHPExcel->getActiveSheet()->setCellValue('A' . $rowCount, $sku);
$objPHPExcel->getActiveSheet()->setCellValue('C' . $rowCount, "Jewels");
$objPHPExcel->getActiveSheet()->setCellValue('D' . $rowCount, "simple");
$objPHPExcel->getActiveSheet()->setCellValue('E' . $rowCount, "Jewelry/" . $finalGender . "/" . $jewelType);
$objPHPExcel->getActiveSheet()->setCellValue('F' . $rowCount, "Default Category");
$objPHPExcel->getActiveSheet()->setCellValue('G' . $rowCount, "base");
$objPHPExcel->getActiveSheet()->setCellValue('K' . $rowCount, $brand);
$objPHPExcel->getActiveSheet()->setCellValue('W' . $rowCount, $description);
$objPHPExcel->getActiveSheet()->setCellValue('AA' . $rowCount, "No");
$objPHPExcel->getActiveSheet()->setCellValue('AC' . $rowCount, $gemColor);
$objPHPExcel->getActiveSheet()->setCellValue('AD' . $rowCount, $gemType);
switch ($finalGender){
case "Women's": $objPHPExcel->getActiveSheet()->setCellValue('AE' . $rowCount, "Women");break;
case "Men's": $objPHPExcel->getActiveSheet()->setCellValue('AE' . $rowCount, "Men");break;
default: $objPHPExcel->getActiveSheet()->setCellValue('AE' . $rowCount, "Child");
}
$objPHPExcel->getActiveSheet()->setCellValue('AG' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('AK' . $rowCount, $jewelType2);
$objPHPExcel->getActiveSheet()->setCellValue('AN' . $rowCount, $metalColor);
$objPHPExcel->getActiveSheet()->setCellValue('AO' . $rowCount, $metalType);
$objPHPExcel->getActiveSheet()->setCellValue('AU' . $rowCount, $msrp);
$objPHPExcel->getActiveSheet()->setCellValue('AV' . $rowCount, "Use config");
$objPHPExcel->getActiveSheet()->setCellValue('AW' . $rowCount, "Use config");
$objPHPExcel->getActiveSheet()->setCellValue('AX' . $rowCount, $name);
$objPHPExcel->getActiveSheet()->setCellValue('BB' . $rowCount, "Product Info Column");
$objPHPExcel->getActiveSheet()->setCellValue('BD' . $rowCount, $price);
$objPHPExcel->getActiveSheet()->setCellValue('BE' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('BH' . $rowCount, $description);
$objPHPExcel->getActiveSheet()->setCellValue('BN' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('BO' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('BU' . $rowCount, "4");
$objPHPExcel->getActiveSheet()->setCellValue('BY' . $rowCount, $qty);
$objPHPExcel->getActiveSheet()->setCellValue('BZ' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('CA' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('CB' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('CC' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('CD' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('CE' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('CF' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('CG' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('CH' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('CI' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('CK' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('CL' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('CM' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('CN' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('CO' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('CP' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('CQ' . $rowCount, "1");
$objPHPExcel->getActiveSheet()->setCellValue('CR' . $rowCount, "0");
$objPHPExcel->getActiveSheet()->setCellValue('CS' . $rowCount, "0");
}
if($categoryRow == 1){
$objPHPExcel->getActiveSheet()->setCellValue('E' . $rowCount, "Brands/" . $brand);
$objPHPExcel->getActiveSheet()->setCellValue('F' . $rowCount, "Default Category");
}
$rowCount++;
}
}
$objWriter = new PHPExcel_Writer_CSV($objPHPExcel);
$objWriter->save('D:\Websites\Utilities\PHPUtils\Export\\' . $fileName);
}
上面是导致错误的脚本,它是从主要调用的。
require_once(__DIR__ . './PHPExcel/ExcelUtil.php');
require_once(__DIR__ . './SOAP/SoapUtil.php');
$data = ExcelUtil::ExcelToArray("WJ\\Jewels\\all_jewels.csv");
ExcelUtil::WJ_JewelsToExcel($data, "WJ\\Jewels\\all_jewels.csv");
PHP&amp;解释器配置正确。
答案 0 :(得分:1)
好吧所以它实际上既不是我的脚本,也不是PHP,而是我试图转换的实际EXCEL文件。保存原始CSV文件时出错了,并删除了所有逗号,所以它是长字符串+500.000个字符,猜测网络服务器在解析时遇到问题,因为它很长。
问题解决了,错误的CSV文件!