PHPlimitrequest bucket leakage has been attacked by friends in recent days, leading to CDN bandwidth spikes and some page requests have also been affected. In addition to Nginx ngx_http_limit_req_module, some optimizations are also required at the PHP level to avoid the impact of Nginx 503 error on user experience.
After a simple discussion, a solution is provided: when the number of requests per second (based on each session sid) exceeds 3, the verification code is displayed and access to all pages is prohibited, the verification code is entered successfully.
When a user requests a verification code, the following verification page is displayed:
To reduce code changes, we add a parent class for each front-end controller class to control the number of requests at the program entry. the code snippet is as follows:
Finally, we will show you the results :)
After the release, the response of the verification code page is faster, the number of requests increases slightly, the total bandwidth usage is reduced by nearly 10 times, and the traffic is also significantly reduced.