0

We have an application that contains among other things a sitemap. The sitemap has 10k entries and is about 1.5Mb in size. The application is run in Google Cloud Run in production, and in Docker locally.

Whenever we request the sitemap locally with 10k entries there are no issues. It just downloads fine. When we try this on Cloud Run however it's sometimes fine, but most of the time it just returns a chunk (not the same every time, sometimes about 200Kb, sometimes about 400Kb, sometimes about 1000Kb) and then stops. The HTTP connection remains open though until one minute has passed since the start of the request and then it times out. Both PHP-FPM and NGiNX don't give clear indication of what might be going on.

As a workaround we're now writing the file to disk and using X-Accel-Redirect to tell NGiNX to serve the file directly. This works without fail (and is fast, about 400ms).

So, even though I'm glad it works now I'm left with two questions:

  1. Why wouldn't this work from PHP directly?
  2. Is there some cut-off point I need to know about after which this behaviour starts?

If it matters, we have fastcgi_buffering off in NGiNX because of Google Cloud Run website timeouts when content length is between 4013-8092 characters. What is going on?. Other than that it's a typical NGiNX setup. gzip is enabled, but disabling it did not help.

rpkamp
  • 811
  • 4
  • 14
  • 1
    You mention no problem when serving the sitemap as a file through Nginx. How are you serving the file when you have a problem? Show the PHP code that reproduces the problem. This [guide](https://stackoverflow.com/help/minimal-reproducible-example) should help with the required details. I use PHP often in Cloud Run without zero issues. Tip: you do not need Nginx as your proxy in Cloud Run. Cloud Run supports Nginx, but it is often just another layer adding latency. – John Hanley Aug 12 '23 at 17:53
  • Well, the PHP code to generate the XML is exactly the same in both cases, only it does _not_ work when PHP `echo`s out the response and it _does_ work when PHP writes the response to disk and then sends an `X-Accell-Redirect` header with the location to tell NGiNX to serve that file. It's just a loop of 10k sitemap entries generated using SimpleXML, obtainted by calling `saveXML()`. – rpkamp Aug 20 '23 at 18:16

0 Answers0