Everyone knows Kron, who according to the schedule will execute the scripts you need. But my task is a little different and I think it’s just not worth it. There is a site with registered users. If no one is logged on to the site, then the crown is not necessary - no schedule for launching scripts is needed. The site stands unchanged. But after someone logged in and roughly speaking pressed a button, the sequence of running different scripts should start. These scripts can take from a couple of minutes to a couple of hours, but the nuance is that the user can even leave the site, close all the pages, but the scripts should continue their execution. Please tell me, who knows how this can be implemented?

I will clarify. Scripts can be from ten to hundreds and thousands. And the main criterion - every next script should be launched immediately after the previous one finishes its work. And if I put Kron, since I know the minimum interval for running scripts is 1 minute, I have to constantly wait - not good :(

    2 answers 2

    crown :) Crown each, say, an hour runs a script.

    The user presses the button, a line with the task / lines with the tasks appears in the database.

    The same kind of script climbs into the database, searches for outstanding tasks and starts them in whole or in part, and then falls asleep. The task writes to the database whether it is executed or not. If yes, it no longer starts; if not, it is in the database about this entry.

    If the "same script" did not find a single job, he falls asleep.

    • I will clarify. Scripts can be from ten to hundreds and thousands. And the main criterion - every next script should be launched immediately after the previous one finishes its work. And if I put Kron, since I know the minimum interval for running scripts is 1 minute, I have to constantly wait - not good: ( - Dzedzik
    • 2
      Thousands of scripts - this is not gut. In any case, especially if they work simultaneously. =) Each next can try to start a neighbor, if the total execution time allows (30s or what is your limit). If not allowed - see above. - knes
    • Well .. The script is actually the same, it just comes in different parameters. It should look as if this script performs some step-by-step tutorial, and there should be no pauses from step to step. To run this script once, so that it performs each step in a cycle, too, is a bit dumb - it can work for a couple of hours - I have not seen this in my own experience. Therefore, I think it is better to launch these “steps” consistently, but how to do it without pauses ...? - Dzedzik
    • Without pauses, this can be done recursively by calling curl, file_get_contents, or include. Exactly as in the cycle. The signal to the ostrovka, as I already wrote, should be time. 30 seconds worked, 30 rested. For 30 seconds, you can shovel a few gigabytes of information, if anything, with the right approach. An example for a rather long operation - deploying a database from a dump: read the contents of a file line by line. In the loop, memorize the line number. if time runs out, write down the file number and name. On the crown you start not from the beginning, but from this number. - knes
    • Clear. Well, probably, we will stop at this. I will try. Many thanks for the tips! - Dzedzik

    There is an additional table, file, etc. In her (him) write the start of your scripts, maybe it's just 1 unit.

    And cron will still have to run so that he looked at this file, and if there is a record "1" then execute your commands as many times as you like.