Is it right to run bash- script with such a delay?

while true; do php -f /.../script.php sleep 0.5 done 
  • Of course wrong. Regardless of the goals and system architecture. Or did you expect another answer? - user6550
  • @klopp, can you explain why wrong? And how, in this case, run the script with a delay of 0.5 seconds? - ModaL
  • If you have a desire to run a certain script at such an interval, something is wrong on your level. Or, rather, the levels for more, much more. Starting with the statement of the global problem and going down to the implementation of its subtasks. - user6550
  • one
    @ModaL oh, well, that is, a rotten business in advance, as it was thought :) - user6550
  • one
    Well, everything will be for the first time. Just think about what account the auction participant will post to YOU ​​if something happens on the way from him to your script. He has a zillion set there, but you have a delay not 0.5, but 0.52 happened. - user6550

2 answers 2

in the gnu / linux operating system, the implementation of the /bin/sleep program, in addition to the requirements of the posix standard , supports not only an integer argument, but also floating point numbers .

so the choice for the programmer: focus on posix- compatibility or gnu- compatibility.

    In this task, one should not sleep, but check the present time with an accuracy of less than a second. A process should be constantly hanging, checking the current time with microseconds, say, in 0.02 seconds, and comparing it with the expected next “start” time. The time has come for the next half-second - the process starts the actual command to make a bet.

    That waiting for the next 0.02 seconds can be trusted to sleep.

    If the auction and the bot are running on different servers, it would be nice to somehow synchronize the clock with them with great accuracy - maybe by making your own implementation of the NTP similarity.