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

Mickaël Leger
  • 3,426
  • 2
  • 17
  • 36
MarvinLeRouge
  • 444
  • 5
  • 15
  • Are you talking about PHP scripts here? Then why file_get_contents, and not include/require …? – misorude Oct 22 '18 at 08:27
  • Those are php scripts, which should be called via full url : it's in codeigniter, so it needs to respect the routing process. – MarvinLeRouge Oct 22 '18 at 08:31
  • use` fopen(); fclose();` or `stream_set_timeout();` – Leo Tahk Oct 22 '18 at 08: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. – misorude Oct 22 '18 at 08:36

1 Answers1

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
Andrea Golin
  • 3,259
  • 1
  • 17
  • 23