How to make the code run continuously and the server does not stop because of the time limit for execution?

This is necessary for the functioning of the bot in the "game". A bot can be seen by all players, its movement and actions can also be seen without delay. That is, it should be run on the server side, and run continuously. I started to create a bot just now, and immediately thought about this problem ...

In the middle of the "perpetual cycle" I wanted to use sleep() to delay actions.

How do you like this implementation? This is the first thing that came to mind, and did not invent anything better. If you have ideas or experience in such things, I will be happy to hear.


    3 answers 3

    Two options:

    1. constantly running script - it is launched not through a browser, but on a server, like a daemon (“demon”), it hangs in your memory and constantly does something there. For example .
    2. if the game is more or less incremental, then it is possible to run the php script once every 1 or 5 minutes, again, not via the web, but the command line (CLI).
    • The first is more suitable, and thanks for the example. I will try - Andrew Stifurak
    • Or try running the script via cron.php, although I could be wrong! - spoilt 2:41 pm

    I did this:
    The script controls its execution time, and when it becomes more than 20, it saves the result of the work, asynchronously calls itself and makes die.
    In contrast to the launch of the crown, this method ensures continuous operation and the impossibility of simultaneous operation of two copies.
    Unlike the daemon, this method will work on hosting that does not provide demons.

      Remarkable function sets the runtime limit; if you pass zero, there is no limit.

      • it if the hosting provider does not cut off. - Sergey