In general, there is a site promotion. Users add tasks, for example, subscribe to Andrey, or like a record, and others perform these tasks. So, yesterday I decided to write a bot that will perform tasks for you. In PHP and JS. Only 2 queries are added to the database. Changes in the job counter and the charging of coins to the user. The delay is 20 seconds. That is, a request is sent to the server every 20 seconds. Delay view:

setTimeout(function() { _bot._reload(); }, 20000); 

They began to use a lot of the bot, but to change the delay by 1 second, for example, and thus, arrange a self-hostess site. So I wanted to ask. There is such a function sleep () , set sleep (20), and setTimeout naturally removed. And it just became so slow to load everything so that the site was completely out of reach. Why does sleep (20) work such wonders?

    1 answer 1

    Because, as I understand it, you have inserted sleep into a PHP script and, of course, now the return page to the browser lasts more than 20 seconds and the site is "hanging". That's all the magic.

    • @ReinRaus, in php the script inserted, yes. But what to do then? - ModaL
    • one
      Make in PHP limit requests from the user, on the client side will not work. - ReinRaus
    • check for example at sessions, and compare how much time has passed, if less than 20 seconds, then talk about it) - Pavel Dura
    • Only it is necessary to take into account that the session identifier may not be transmitted and then a new session will begin. Sessions should be used if they are used to identify the user. - ReinRaus
    • @ReinRaus, the session is still that nonsense. Third-party server, they will cost and be forgotten. I'll make it cooler. - ModaL