phptimeoutfile-get-contentslong-running-processes

PHP long running scripts in sequence


I have the following problem : in a php script, I have to launch a first script, then a second one. The second one must not start before the first one has finished.

Problem : the two scripts are long-running (can take up to some hours). So, if I use file_get_contents on each script url, I can make the first one run (via set_time_limit 0), but the file_get_contents times out, so I have an error, and the second one never runs.

Note : those scripts run on localhost on a linux machine, on which I am admin. I can do whatever I need to make this work.

Thanks


Solution

  • Execute them via command line, and chain them with &&, so the second one will fire only if the first has finished correctly

    php script1 && php script2
    

    Or chain with ; if you just want the second to trigger after the first, regardless of exit status

    php script1; php script2