If you want to immediately respond to the browser, try flush() when you want to dump the output buffer into the browser. In addition, you may need to disable compression (e.g. gzip), which may affect output buffering.
However, taking this into account, you completely disagree about this. All the user has to do is open another tab / update and the server will check the login details again, so sleep() will not have the effect that you think will be.
I really developed something similar to this, and this is what I did:
Create a database table called fail_logins and the other called login_bans, and both are based on IP address. Each time the user provides incorrect information, add an entry to the failed_logins table. What you want to do is specify it so that after the first login the user is blocked for 5 seconds, after the second it lasts up to 15 seconds and 3 or more for a certain period of time (for example, 2 hours) the user is prohibited for 45 seconds . All this is done on the server side, so the user can not do anything to circumvent the ban. Therefore, you will have to check your IP address every time they access the page to see if their IP address is denied.
Then, on the client side, a countdown timer will be displayed containing the number of seconds remaining in the ban, and disable the submit button.
Mike source share