This article describes how php-developed websites can cope with high-traffic and high-concurrency problems. For more information, see. How can php websites cope with high traffic and high concurrency? First, check whether the server hardware is sufficient to support the current traffic. A common P4 server generally supports up to 0.1 million independent IP addresses per day. if the traffic is larger than this, configure a dedicated server with higher performance ., Otherwise, it is impossible to completely solve the performance problem. Second, optimize database access. It is recommended that the front-end be completely static, and there is no need to access the database at all. However, for websites with frequent updates, static features often cannot meet certain functions. The caching technology stores dynamic data in cached files. The ** page calls these files directly without having to access the database. WordPress and Z-Blog Use This caching technology in large quantities. If you cannot avoid database access, you can try to optimize the database query SQL. avoid using statements such as Select * from. only the results you need are returned for each query to avoid a large number of SQL queries in a short period of time. Third, prohibit external leeching. Image or file leeching on external websites often results in a lot of load pressure. Therefore, we should strictly limit external leeching on images or files. Fortunately, at present, we can simply use refer to control leeching, apache can disable leeching through configuration. IIS also has some third-party isapis to implement the same function. To prevent leeching by spoofing refer code, you can add watermarks to images. Fourth, control the download of large files. Large file downloads consume a lot of traffic, and for non-SCSI hard disks, large file downloads consume CPU, reducing website response capabilities. Therefore, we recommend that you do not download large files larger than 2 MB. Fifth, use different hosts to distribute traffic and place files on different hosts to provide different images for users to download. For example, if you think that the RSS file occupies a large amount of traffic, use FeedBurner or FeedSky and other services to store the RSS output on other hosts. in this case, the traffic pressure of other users is mostly concentrated on the FeedBurner host, RSS does not occupy too much resources. Sixth, use the traffic analysis and statistics software. Install a traffic analysis and statistics software on the website to instantly know where traffic is consumed and which pages need to be optimized. therefore, precise statistical analysis is required to solve traffic problems. The traffic analysis statistics software I recommend is Google Analytics ). I think it works very well when using it. I will introduce some common knowledge and skills of Google Analytics in detail later .. Table sharding 2. read/write splitting 3. frontend optimization. Replacing Apache with Nginx (front-end server load balancer) mainly depends on whether the distributed architecture is in place. the optimization of mysql and cache is limited. with the distributed architecture, after PV increases, you only need the heap machine to expand the capacity. Optimization experience: First, learn to use explain statements to analyze select statements, optimize indexes and table structures, and then use memcache and other caches reasonably to reduce mysql load. Finally, try to use facebook's hiphop-php to compile PHP to improve program efficiency. |