ab command principle
Apache's ab command simulates multi-threaded concurrent requests to test server load pressure. It can also test the pressure of other web servers such as nginx, lighthttp, IIS, etc.
The ab tool that comes with Apache (the PHP environment used is the WAMP integrated environment, the ab tool is located in D:\wamp\bin\apache\Apache2.2.21\bin) is very easy to use. The ab command has very low requirements on the computer that issues the load. It will not occupy a lot of CPU or memory, but it will cause a huge load to the target server. Therefore, it is a necessary medicine for some DDOS attacks. Suitable for all. You must also be careful when using it yourself. Otherwise, too much load is applied at once, causing the target server to crash due to running out of memory and having to hard restart, which is not worth the loss.
In the case of insufficient bandwidth, it is best to test on the local machine. It is recommended to use another or multiple servers on the intranet to test through the intranet. The data obtained in this way will be much more accurate. . Remote stress testing of web servers often yields unsatisfactory results (due to excessive network latency or insufficient bandwidth)
Download and install:
;O=A
Find httpd- 2.2.21-win32-x86-no_ssl.msi
Parameter documentation:
Run:
Under Windows system, open the cmd command line window and navigate to the bin directory of the apache installation directory
cd C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin
Type the command:
ab -n 800 -c 800 http://192.168.0.10/
(-n issues 800 requests, -c simulates 800 concurrency, equivalent to 800 people accessing at the same time, followed by the test url)
ab -t 60 -c 100 http://192.168.0.10/
Send requests within 60 seconds, 100 requests at a time.
//If you need to bring parameters in the url, do this
ab -t 60 -c 100 -T "text/plain" -p p.txt http://192.168.0.10/hello. html
p.txt is in the same directory as ab.exe
p.txt. You can write parameters in it, such as p=wdp&fq=78
Explanation of result parameters:
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Licenseed to The Apache Software Foundation,
Benchmarking 192.168.0.10 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Finished 800 requests
Server Software: Microsoft-HTTPAPI/2.0 Represents the web server being tested Software name
Server Hostname: 192.168.0.10 Represents the requested URL host name
Server Port: 80 Represents the tested Web server software Listening port
Document Path: Root absolute path. Through the suffix name of this file, we can generally understand the type of the request
DOCUMENT LENGTH: 315 bytes.
Concurrency Level: 800 represents the number of concurrent users. This is one of the parameters we set. ## FAILED Requests: 0 Failure Requests
Write Errs: 0
Non-2xx Responses: 800
Total Transferred: 393600 bytes Total Transmission
HTML Transferred: 252000 bytes HTML content Transmission volume
Requests per second: 875.22 [#/sec] (mean) Throughput - number of requests per second
Time per request: 914.052 [ms] (mean) The time it takes for the server to receive a request and respond to the page
Time per request: 1.143 [ms] (mean, across all concurrent requests) The average time consumed by each concurrent request
Transfer rate: 420.52 [Kbytes/sec] received The average traffic on the network per second, which can help to rule out whether there is The problem of prolonged response time caused by excessive network traffic
Breakdown of time spent on the network:
Connect: 0 1 0.5 1 3
Processing: 245 534 125.2 570 682
Waiting: 11 386 189.1 409 669
Total: 246 535 125.0 571 684
Response status of all requests in the entire scenario. In the scenario, each request has a response time
50% of the user response time is less than 571 milliseconds
The maximum response time is less than 684 milliseconds
Percentage of the requests served within a certain time (ms)
50% 571
66% 627
75% 646
80% 652
90% 666
95% 677
98% 681
99% 682
100% 684 (longest request)
This part of the data is used to describe the distribution of each request processing time. For example, in the above test, 80% of the request processing time None exceed 6ms. This processing time refers to the previous Time per request, that is, the average processing time of each request for a single user.
The above is the detailed content of Detailed explanation of using Apache's ab tool example. For more information, please follow other related articles on the PHP Chinese website!

To protect the application from session-related XSS attacks, the following measures are required: 1. Set the HttpOnly and Secure flags to protect the session cookies. 2. Export codes for all user inputs. 3. Implement content security policy (CSP) to limit script sources. Through these policies, session-related XSS attacks can be effectively protected and user data can be ensured.

Methods to optimize PHP session performance include: 1. Delay session start, 2. Use database to store sessions, 3. Compress session data, 4. Manage session life cycle, and 5. Implement session sharing. These strategies can significantly improve the efficiency of applications in high concurrency environments.

Thesession.gc_maxlifetimesettinginPHPdeterminesthelifespanofsessiondata,setinseconds.1)It'sconfiguredinphp.iniorviaini_set().2)Abalanceisneededtoavoidperformanceissuesandunexpectedlogouts.3)PHP'sgarbagecollectionisprobabilistic,influencedbygc_probabi

In PHP, you can use the session_name() function to configure the session name. The specific steps are as follows: 1. Use the session_name() function to set the session name, such as session_name("my_session"). 2. After setting the session name, call session_start() to start the session. Configuring session names can avoid session data conflicts between multiple applications and enhance security, but pay attention to the uniqueness, security, length and setting timing of session names.

The session ID should be regenerated regularly at login, before sensitive operations, and every 30 minutes. 1. Regenerate the session ID when logging in to prevent session fixed attacks. 2. Regenerate before sensitive operations to improve safety. 3. Regular regeneration reduces long-term utilization risks, but the user experience needs to be weighed.

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!