views:

197

answers:

1

Hello,

I'm using lighttpd as webserver for php application server. The avg. load on this server is about 2-3. MySQL database is separated to another server (it's load ~0.4). How could I scale php application server?

Thank you.

+6  A: 

In a few words, a solution, generally speaking, is to :

  • Have several PHP servers
  • Have another load-balancing server in front of those
    • If you have 3 PHP servers, then, this load-balancer will send 33% of the requests it receives on each PHP server.

The load-balancing server can be some specialized hardware ; or a reverse-proxy, using Apache (see mod_proxy_balancer for example), nginx (see Load Balancing with Nginx, for example), varnish, ...


The most important problems you'll generally face when using several PHP servers instead of ones are related to the filesystem : with several servers, each server has its own disks and filesystem.

For example, if a user is randomly balanced on server 1 for one page, and server 2 for another page, you cannot use file-based sessions : the session will be created on server 1, but will not be found on server 2, later.
In this specific case, you'll have to use another mecanism to store sessions -- store them in a database, or memcached, for example.

Same things with images (uploaded by users, for example) : you'll have to either :

  • Synchronise them between servers
  • Or use some kind of network-drive


Edit after the comment : For the deployment, with several servers, I generally do exactly as I would with only one server.

For more informations on the kind of process I often use, you can take a look at the answer I gave a while back on this question : Updating a web app without any downtime.

The explanation given there is for one server, but to do the same thing on several servers, you can :

  • Upload the archive to each one of your servers
  • Extract it
  • And, at almost the same instant, switch the symlink on all servers
    • At worst, you'll have 2 or 3 seconds of delay between each servers, which means 10 seconds if you have 5 servers ? It's probably not a big problem :-)

(I've done this with up to 7 servers, for one application, and never had any problem)

Pascal MARTIN
Aha, I understand. Thank you. I'm using memcache and DB as session storage. PHP temporary upload folder could be moved to NFS - it will solve problem with uploads. The biggest pain in the ass is application deployment. Maybe there are some good advices how to deploy application on multiple servers? Thank you for you comment!
Kirzilla
@Kirzilla : You're welcome :-) ;; I've edited my answer to provide some informations about the deployment process :-)
Pascal MARTIN
Thank you very much!
Kirzilla