How can I limit the number of requests allowed on the server?
Source: Internet
Author: User
How can I limit the number of requests allowed on the server using PHP? the server can accept up to five requests from a single IP address every 2 seconds. How should we implement it? it should be reasonable to say. You can determine the access path and ip address. The simplest method is to calculate the number of visits for the last access time and the latest access time. of course, to write data to the database, PHP is used to implement, that is, how to limit the number of requests allowed by sess on the server
Can I use PHP to restrict the server to receive up to five requests from a single IP address every 2 seconds.
How to implement it?
------ Solution --------------------
It should be reasonable. You can determine the route and ip address.
------ Solution --------------------
The simplest method is to calculate the number of visits between the last access time and the last access time. of course, you need to write data to the database.
------ Solution --------------------
PHP is used to implement session
------ Solution --------------------
Session_start ();
If (isset ($ _ SESSION ['lasttime']) & time ()-$ _ SESSION ['lasttime'] <2)
Exit;
Else
$ _ SESSION ['lasttime'] = time ();
------ Solution --------------------
Generally, IP addresses and sessions are bundled together.
The number of visits in a few seconds exceeds 100,000.
This is a failure. if this happens, your server has crashed.
------ Solution --------------------
If the COOKIE time is not set, the browser closes the SESSION and becomes invalid.
------ Solution --------------------
Discussion
By the way, what is the actual relationship between SESSION and browser enabling and disabling,
------ Solution --------------------
Discussion
Reference:
Generally, IP addresses and sessions are bundled together.
The number of visits in a few seconds exceeds 100,000.
This is a failure. if this happens, your server has crashed.
Oh, thank you for your guidance !!
A few simple words seem to solve the problem. I originally planned to exist in the database. each IP address corresponds to a record, and then there are access traffic, time, and other fields ..
In fact, I'm curious. what the predecessors said about the crash is probably normal. I really have no idea about this ..
Most ......
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.