我的脚本中有一个函数在通过 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);
}
上面是导致错误的脚本,它是从 main 调用的。
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 和解释器配置正确。