2

There's a function in my script that suddenly causes a 502 Bad Gateway error when running trough PHPStorm. I've never had it before with similar scripts. When I comment it out, I've got no errors at all. How's that possible ?

The script takes info from one excel and converts it to another.

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);
}

Above is the script causing the error, and it's called from a 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 & Interpreter are configured correctly.

jean-max
  • 1,640
  • 1
  • 18
  • 33
TanguyB
  • 1,954
  • 3
  • 21
  • 40
  • Remove static keyword from function signature. – Aniket Singh Dec 12 '16 at 13:00
  • And call it dynamically ? Didn't work. – TanguyB Dec 12 '16 at 13:03
  • Ohh ok. Means this function is within a class. I was assuming outside. By the way add this scripts just before calling the function `error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT); ini_set('display_errors', 'On'); ini_set('xdebug.force_display_errors', 'On'); ` It may help to find exact issue. – Aniket Singh Dec 12 '16 at 13:13
  • what to you mean by "running through PHPStorm"? – leoap Dec 12 '16 at 13:15

1 Answers1

2

Ok so it was actually neither my script, neither PHP, but the actual EXCEL file I was trying to convert. While saving the original CSV file something went wrong, and it removed all the comma's, so it was long string of +500.000 characters, guess the webserver had problems with parsing that as it was to long.

Problem solved, faulty CSV file!

TanguyB
  • 1,954
  • 3
  • 21
  • 40