Home >Backend Development >PHP Tutorial >PHP Program Acceleration Exploration Server Load Test_PHP Tutorial
It is also very common for the server load to be too large and affect the efficiency of the program, and we need to test this. Here I take the most commonly used Apache server as an example.
The Apache server comes with a tool called AB (ApacheBench), which is in the bin directory. Using this lightweight tool we can load test our server to see how it performs under heavy load. ApacheBench can simulate continuous online requests for a specific URL, and it can also simulate several identical online requests at the same time point. Therefore, using ApacheBench can help us simulate the actual online possible situation during website development, and use the simulated The data is used as a basis for adjusting server settings or procedures.
Output at the command line:
./ab -n number_of_total_requests
-c number_of_simultaneous_requests
http://your_web_server/your_php_app.php
For example:
./ab -n 1000 -c 50 http://www.domain.com/myapp.php
AB will issue 50 concurrent requests to http://www.domain.com/myapp.php at the same time , issued 1000 times in total.
The test results may be like this:
Server Software: Apache/2.0.16
Server Hostname: localhost
Server Port: 80
Document Path: /myapp .php
Document Length: 1311 bytes
Concurrency Level: 50
Time taken for tests: 8.794 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 175 4000 bytes
HTML transferred: 1311000 bytes
Requests per second: 113.71
Transfer rate: 199.45 kb/s received
Connection Times (ms)
min avg max
Connect: 0 0 5
Processing: 111 427 550
Total: 111 427 555
The number of requests myapp.php can handle per second is 113.71. Increase the number of requests and see if the server can handle the greater pressure. You also need to adjust Apache's MaxClients, ThreadsPerChild, MaxThreadsPerChild and other parameters, based on the MPM module selection in your httpd.conf.
If you want more detailed information, please go to www.apache.org to check out some more in-depth documentation, including modules and third-party productivity tools. After modifying httpd.conf, restart the Apache server and then use AB to test. You will see the number of requests per second increase or decrease.
Write down the parameters each time, and finally choose the configuration with the best efficiency.
It should be pointed out that in addition to AB, there are many excellent server performance testing software. In addition, if your server is not Apache, please find your own testing method.