# Is it better to upstream php processes via nginx or use a front facing load balancer?

**URL:** <https://www.ruby-forum.com/t/is-it-better-to-upstream-php-processes-via-nginx-or-use-a-front-facing-load-balancer/175208>\
**Category:** NGINX\
**Created:** [September 9, 2009, 6:46pm UTC](https://www.ruby-forum.com/t/is-it-better-to-upstream-php-processes-via-nginx-or-use-a-front-facing-load-balancer/175208 "2009-09-09T18:46:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [September 9, 2009, 6:46pm UTC](https://www.ruby-forum.com/t/is-it-better-to-upstream-php-processes-via-nginx-or-use-a-front-facing-load-balancer/175208/1 "2009-09-09T18:46:22Z")

</div>

Hi,  
Is it better to use a hardware load balancer in front of multiple nginx  
boxes, each running their own php processes or is it better to use  
nginx’s  
upstream functionality and round robin php requests?

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [September 10, 2009, 11:35am UTC](https://www.ruby-forum.com/t/is-it-better-to-upstream-php-processes-via-nginx-or-use-a-front-facing-load-balancer/175208/2 "2009-09-10T11:35:34Z")

</div>

How high traffic have your sites got?

In my system, Nginx plays a role of a LB and static file server. It  
dispatches .php requests to a pool of Apache instances and PHP FCGI. It  
works great for 600 000+ page views per day.

Ilan B. wrote:

> Hi,  
> Is it better to use a hardware load balancer in front of multiple nginx  
> boxes, each running their own php processes or is it better to use  
> nginx’s  
> upstream functionality and round robin php requests?

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [September 10, 2009, 1:49pm UTC](https://www.ruby-forum.com/t/is-it-better-to-upstream-php-processes-via-nginx-or-use-a-front-facing-load-balancer/175208/3 "2009-09-10T13:49:39Z")

</div>

1.6mm page views per day and growing (all dynamic php), this does not  
inclue  
a large number of static files (mostly mp3 files) being served as well.

Nginx is serving both PHP and static files all from the same server.

Main bottleneck right now is PHP processes getting overloaded, probably  
due  
to high number of connections (we are working on reducing this number -  
we  
have some inefficiencies where a single page may make over 120 requests  
before completely loading). The other issue is the number of database  
requests per page can be very high which delays PHP response times and  
increases queue.

Regardless, we need to add another box, but I’m trying to figure out if  
best  
approach is physical LB in front of duplicate nginx boxes, i.e. each box  
serving both PHP and static files OR more complex solution with one of  
the  
boxes acting as master and routing PHP requests via Nginx to other  
boxes,  
etc. as well as possibly adding a static server specifically for images  
and  
mp3 files.

---

<div class="post-metadata">

**Author:** ![iberci](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a3d4f5/32.png) [@iberci](https://www.ruby-forum.com/u/iberci)\
**Post date:** [September 10, 2009, 3:07pm UTC](https://www.ruby-forum.com/t/is-it-better-to-upstream-php-processes-via-nginx-or-use-a-front-facing-load-balancer/175208/4 "2009-09-10T15:07:31Z")

</div>

We use nginx as a pure LB.

All php sessions and static files are shared to all apache 2 webheads  
via OCFS2.

Then we use upstream fair, and removed the need for sticky sessions (  
by using a clustered FS to share the session files to all nodes)

This lets every image/html/php request go to different webheads for  
maximum response for the EU.

Also we wrote it so if nginx gets a proxy error, it marks the webhead  
as bad and reprocess the request until it finds a good webhead to proxy  
to.

Btw use use apache webheads so we can use php as a module rather than  
fcgi and spawn php type methods.

Hope it helps  
David
