1

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

4
  • Are you talking about PHP scripts here? Then why file_get_contents, and not include/require …? Commented Oct 22, 2018 at 8:27
  • Those are php scripts, which should be called via full url : it's in codeigniter, so it needs to respect the routing process. Commented Oct 22, 2018 at 8:31
  • use` fopen(); fclose();` or stream_set_timeout(); Commented Oct 22, 2018 at 8:35
  • You could try and pass a stream context into file_get_contents and specify the timeout via that. (Not sure if -1 for “no timeout” is a valid option.) But that might still run into problems with timeouts on the web server level or something. A script running that long should rather not be called via HTTP in the first place IMHO. Commented Oct 22, 2018 at 8:36

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

With exec and the &&, it's just what i needed. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.