dougang1965 2010-04-15 10:28
浏览 26
已采纳

如何横向扩展php应用服务器?

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.

  • 写回答

1条回答 默认 最新

  • duanmao7553 2010-04-15 10:36
    关注

    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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 eclipse连接sap后代码跑出来空白
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案