开发者

How to handle high website traffic in PHP [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly br开发者_Python百科oad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have a website, and the server is always down. When many people access the website, the server becomes very very slow. I am using PHP. Any suggestion for this?

Thank you a lot.


Yes - suggestions:

  • better server
  • better host
  • better code
  • worse content (helps keep people from taking down your site by visiting it - those darn users)
  • upgrade hosting account to allow for more bandwidth/mo
  • pay a server administrator to look at your site/hosting/server...etc


You may need to cache some data instead of hitting the database every request. Often the database is the bottleneck. You should also check how your server handle the traffic. You may need to have a better hosting server.


That is a loaded question, but here are some thoughts (and order can vary, but some of these may be obvious issues):

  1. Improve the hardware
    • Do you have enough RAM?
    • Are you using multiple servers and a (many?) load balancer(s)
    • What are your connection speeds like? Do you need greater bandwidth
  2. Optimize your code -- when in doubt try it another way and benchmark
    • Keep the number of calls to the database to a minimum.
    • Make sure you're working with the language (are you using the Spl libraries?) ) )
  3. Cache, cache, cache. If something is not likely going to change it may be faster to 'leave it built' -- if you've reason to believe that something will persist between a number of HTTP requests, then it is probably faster to place it inside of a file which can be output through readfile, include, or require, instead of as a database request, XML, JSON, YAML, etc.
  4. Use a faster server architecture (lighthttpd instead of Apache)simply store it in a finalized form on a hard drive.
  5. Compile you PHP with Hip Hop or the like

Just as a note as to why I chose this order:
I put hardware first because that is something which is easy and obvious. If you're dealing with an outdated hardware architecture and you have only one server trying to handle tens of thousands of HTTP requests simultaneously, the hardware may very well be the fastest, easiest solution. Obviously, it is not the end all and be all and I can totally understand why it could be moved below code optimizing.

I put caching after optimization because I view caching as an important optimization. Basically, it is important enough to include separately, but not important enough to supersede its rightful parent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜