0

I have tried several times to print a string by using the "echo" method but it seems to throw a 502 Bad Gateway when the string gets too large?

I'm using the PhpStorm's built-in webserver.

Does anyone knows how to fix this issue or could provide a workaround?

I have tried using multiple strings and apparently only short ones are giving me a 200 response.

The sever throws a 502 in the example below, but if I remove the part "\"maths\" ..... closing bracket or anything else to make it much shorter it gives back a 200. This includes non-JSON strings as well.

<?php
header("Content-Type:application/json");
echo "{
    \"quiz\": {
        \"sport\": {
            \"q1\": {
                \"question\": \"Which one is correct team name in NBA?\",
                \"options\": [
                    \"New York Bulls\",
                    \"Los Angeles Kings\",
                    \"Golden State Warriros\",
                    \"Huston Rocket\"
                ],
                \"answer\": \"Huston Rocket\"
            }
        },
        \"maths\": {
            \"q1\": {
                \"question\": \"5 + 7 = ?\",
                \"options\": [
                    \"10\",
                    \"11\",
                    \"12\",
                    \"13\"
                ],
                \"answer\": \"12\"
            },
            \"q2\": {
                \"question\": \"12 - 8 = ?\",
                \"options\": [
                    \"1\",
                    \"2\",
                    \"3\",
                    \"4\"
                ],
                \"answer\": \"4\"
            }
        }
    }
}";

I couldn't find any error logs. The only thing that shows when the string is too large is a 502 Bad Gateway.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
  • Put these lines above of your script `error_reporting(E_ALL); ini_set('display_errors', 1);` maybe your error disabled by default on your php version – MAZux Jul 13 '19 at 20:16
  • @MAZux Thanks for the quick response. I do have errors enabled and I also tried the the script above to make sure of it, but the echo code doesnt throw any errors. – MisterProbs Jul 13 '19 at 20:29
  • Probably you are not returning a Valid JSON. Try removing Headers and see if it prints correctly. – ascsoftw Jul 14 '19 at 05:28
  • @user1309690 the json is valid according to every json validator I have tried, but I did try removing the header but I ended up with the same result. Also as mentioned before it also happends with non-json strings. – MisterProbs Jul 14 '19 at 09:45
  • I can reproduce it. Please note this is a communication issue between PhpStorm's builtin web server (written in Java and only suitable for static assets) and PHP's builtin web server (written in PHP and only suitable for PHP code) and, IMHO, most likely a bug in PhpStorm. Does the IDE log ("Help/ Show Log in Explorer") show something relevant for you? I get "java.lang.IllegalArgumentException: minimumReadableBytes: -1003 (expected: >= 0)", which doesn't say much to me. – Álvaro González Jul 14 '19 at 11:02
  • BTW, I hope this is just a proof of concept because that's the most unmaintainable way to emit JSON. – Álvaro González Jul 14 '19 at 11:04
  • @ÁlvaroGonzález yes this is just a proof of concept, but the error Im getting in my idea.log is the following "ERROR - ins.io.ChannelExceptionHandler - JDK: 1.8.0_202-release;" – MisterProbs Jul 14 '19 at 11:25
  • If it's 502 and PhpStorm's built-in web server is used .. then it might be an issue with built-in web server (e.g. https://youtrack.jetbrains.com/issue/WEB-31859). **P.S.** A bit unrelated to the actual issue ... but if you need long or multi-line strings .... try HEREDOC/NOWDOC syntax. – LazyOne Jul 14 '19 at 13:52

1 Answers1

0

Seems like it a known bug in the phpstorm JavaVM.

Swapping to a apache server did the trick for me. Instructions can be found here PHPstorm 10.0.3 Error 502 Bad Gateway (Due to JavaVM?)