SOLVED -- Can nginx render in-process php pages?

I'm working on migrating to Linode and followed the LEMP guide in the library. Everything is working great except my pages don't render until all php processing is done.

My old server (which uses Apache) shows pages as PHP progresses. This actually matters quite a lot because there's a few pages that take a long time to load and showing nothing makes me/users mad/confused.

Is this a limitation of Nginx? Would it work the way I need it to if I upgraded to php-fpm?

5 Replies

Set fastcgimaxtempfilesize to 0 in your nginx.conf and restart nginx

If your PHP page takes so long to load that it makes your users mad, you have a bigger problem. Displaying some parts of the page early on is only a band-aid. Have you tried caching the part that takes so long to generate? Can you generate the page without that part, and load the rest using AJAX or an iframe?

Thanks for the help, but my problem turned out to be a PHP issue. It seems likely that my old server was using implicit_flush, even though it was off in the ini file. Maybe it was using a different ini than I thought.

Turning on implicitflush made the new server behave as I'd expect. I've read that implicitflush is to be avoided though, so I've turned it off and am sprinkling flush() calls in the code where needed instead.

@Dylan:

Thanks for the help, but my problem turned out to be a PHP issue. It seems likely that my old server was using implicit_flush, even though it was off in the ini file. Maybe it was using a different ini than I thought.

Turning on implicitflush made the new server behave as I'd expect. I've read that implicitflush is to be avoided though, so I've turned it off and am sprinkling flush() calls in the code where needed instead.

I agree with the previous replies, that if you need flush() anywhere except very specific cases that require partial content (I can think of some ajaxy situations where it might be handy), you're probably doing it wrong.

For anyone who finds this later, I never did get php's flush() to work with nginx (after trying many different buffer settings). Ended up going back to Apache.

I agree that relying on flush() is not ideal. The site was designed when the database was quite a bit smaller! Most pages load in 1 or 2 seconds though and when a user hits a longer load, flush() can at least show the top half of the page very quickly. It's a good enough bandaid for me.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct