27
linuxxx
6y

Finally got my nginx config to work properly (it shouldn't work but it does so I'm not fucking touching it).

Request with curl: check, right http code and getting data back properly.

Request with any browser (with and without incognito): right http code, AND ONLY SEEING DATA WHEN I ECHO ANYTHING BEFORE SENDING THE RESPONSE WITH PHP. When I don't echo whatever before sending the response, the browser doesn't see the data but DOES see the http status code.

HOW?!

Comments
  • 4
    I have no clue what you are doing wrong... There isn't that much to do wrong.. You know about nginx -t do you?
  • 1
    @epse Yup and it shows OK.
  • 2
    Havr you checked your output buffering settings?
  • 1
    @linuxxx is it just a plain php with nginx in front?
  • 1
    @FMashiro No clue what and where that is, please enlighten me!
  • 2
    @epse Some rewrite stuff but then again, when calling through curl it all shows well
  • 3
    @linuxxx php has some weird stuff with output buffering, some very convoluted settings as far as I can remember, but basically, look into the functions starting with "ob_" like "ob_start()" for example.

    Sometimes your configuration is fucked up and you either need to edit it or use "ob_flush()" to output the buffer.
  • 1
    @FMashiro Ohh that, yes.
    I'll check but also check my comment above yours :)
  • 1
    @FMashiro what? That is weird, never encountered that
  • 2
    @linuxxx have you checked that this setting is off?

    http://nginx.org/en/docs/...
  • 2
    @epse I've had some weird stuff with configuration conflicts causing output buffering to turn on when I didn't want it to and turn off when I did want the buffering, was à few years ago tho, so not that up to date...
  • 4
    Obligatory "use Node" comment to annoy @linuxxx 😉
  • 0
    Are you sure it is nginx?

    You said when you echo all good, no echo no data.

    Lazy loading? I know not related but when dealing with Entity Framework (DotNet) if we are calling a navigation property of a table (foreign key relation) and lazy loading is enabled, result is always null, but right after if we call it again data is there.

    I'm not a php dev, but what if that echo caused that tiny delay needed for data to get ready and be sent? Though you are echo'ing your data but still your scenario reminds me of EF and lazy loading
  • 3
    @Root You mean use Dotnet on windows server, that will annoy the hell out of him lol
  • 2
    @gitpush PowerShell?
  • 1
    @ewpratten aaah even better lol

    Jokes aside, I hear that powershell is actually powerful, I never used it tbh, never been good in terminal stuff under MS OS's :\
  • 0
    @Root Ohhh I like node as well!
  • 2
    @gitpush it was nginx which wasn't (for some fucking reason) putting in right cors headers.

    Hacked a solution together with php now which works!
  • 0
    Curl is dumb hammer which does not add any headers by itself. Browsers do use them frequently and check if they are correct.
  • 0
    @2lazy2debug Half a year or more :)
Add Comment