How does PHP solve the problem of high traffic and high concurrency

  • 2020-05-09 18:16:33
  • OfStack

First, make sure the server hardware is sufficient to support the current traffic.

The average P4 server 1 can support up to 100,000 unique IP per day.
Then you must first configure a dedicated server with higher performance to solve the problem

, otherwise how the optimization can not completely solve the performance problem.

Second, optimize database access.

It would be best if the foreground were completely static, without having to access the database at all, but for frequently updated websites,
Staticization often fails to satisfy certain functions.

Caching technology is another solution, which is to store dynamic data in a cache file and call dynamic web pages directly
These files, rather than having to access the database, are heavily used by both WordPress and Z-Blog. I
I have also written an Z-Blog counter plug-in, which is also based on this principle.

If you really can't avoid database access, try to optimize the database's query SQL.avoid it
With statements like Select * from, each query returns only the results it needs to avoid being large in a short period of time
Volume SQL query.

Third, prohibit external hotlinking.

External web site images or files hotlinking often bring a lot of load pressure, so should be strictly limited to external
Hotlinking can be used to control hotlinking and Apache by refer
It can be configured to disable hotlinking, and IIS has a third ISAPI that does the same. when
However, it is possible to fake refer to achieve hotlinking through code. However, currently, there are not many people who deliberately fake refer hotlinking.
You can ignore it for a while, or you can use a non-technical solution, such as adding a watermark to an image.

Fourth, control the downloading of large files.

Large file downloads take up a lot of traffic, and for non-SCSI hard drives, large file downloads consume a lot of data
CPU, making the website less responsive. Therefore, try not to offer large file downloads over 2M if required
Yes, it is recommended to put the large file on another server.

Fifth, use different host to divert the main flow

Place files on different hosts, providing different images for users to download. For example, if you feel that the RSS file is occupied
High traffic, then use FeedBurner or FeedSky services to put RSS output on other hosts, which
The traffic pressure of others is mostly concentrated on the host of FeedBurner, while RSS does not occupy too many resources.

Sixth, use traffic analysis and statistics software.

Install a traffic analysis and statistics software on your website to instantly know where you are consuming a lot of traffic and which pages
The surface needs to be optimized again. Therefore, accurate statistical analysis is needed to solve the flow problem. I recommend that
The traffic analysis and statistics software used is Google Analytics (Google analysis). I feel it in the process of using it
It works very well, and I'll go into some common sense and tricks on Google Analytics later.

Related articles: