The solution of large traffic and high concurrency of PHP website

Source: Internet
Author: User
Tags php website dedicated server
This article describes the PHP development of the Web site how to deal with large traffic and high concurrency problems, the need for friends to refer to it.

How does a PHP website handle high traffic and concurrency?

First, verify that the server hardware is sufficient to support the current traffic. Ordinary P4 servers can generally support up to 100,000 independent IPs per day, and if the traffic is larger than this, configure a dedicated server with higher performance. , otherwise optimization will not solve the performance problem completely.

Second, optimize database access. The front desk is best completely static, can not access the database at all, but for frequently updated sites, static often does not meet certain functions. Caching technology that stores dynamic Data in a cache file, * * Pages call these files directly without having to access the database, and WordPress and Z-blog Use this caching technology in large numbers. If you do not avoid access to the database, you can try to optimize query SQL for the database. Avoid using a statement like Select * from, each time the query returns only the results you want, avoiding a large number of SQL queries over a short period of time.

Third, prohibit the external hotlinking. External Web site picture or file hotlinking often bring a lot of load pressure, so should strictly restrict the external to their own picture or file hotlinking, fortunately, can now simply through refer to control the hotlinking, Apache itself can be configured to prohibit hotlinking, IIS also has some third-party ISAPI that can implement the same functionality.

To prevent the forgery of refer code hotlinking, you can add watermarks to the image.

Four, control the download of large files. Large file downloads can consume a lot of traffic, and for non-SCSI hard drives, a large number of file downloads can consume CPU, resulting in reduced responsiveness. Therefore, try not to provide more than 2M of large file download, if required to provide, it is recommended to put large files on another server.

Five, use different host to divert the main traffic to put the files on different hosts, provide different images for users to download. For example, if you feel that the RSS files occupy a large amount of traffic, then use services such as FeedBurner or Feedsky to put the RSS output on other hosts, so that others access to the traffic pressure is mostly concentrated on FeedBurner host, RSS does not occupy too much resources.

VI, use traffic analysis statistics software. Install a traffic analysis and statistics software on the website to instantly know which places are consuming a lot of traffic and which pages need to be optimized, so it is necessary to have accurate statistical analysis to solve the traffic problems. I recommend that the traffic analysis statistics software be Google Analytics. I used to feel that it worked very well, and I'll cover some of Google Analytics's use of common sense and skills later on: Table 2. Read-write Separation 3. Front-end optimization. Nginx Replacement Apache (front-end load balancing) is mainly to see whether the distributed architecture is in place, MySQL and cache optimization is a limited optimization, and the distributed architecture to make, PV growth, only need to heap machine capacity to expand. Optimization experience: First, learn to use explain statements to analyze SELECT statements, optimize the index, table structure, and secondly, reasonable use of memcache cache, reduce the load of MySQL. Finally, try compiling PHP with Facebook's hiphop-php to improve program efficiency.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.