I have the following PHP code:
shell_exec("(traceroute odesk.com > trace.txt;echo 'traceIsDone'>>trace.txt) &");
This line takes 50 seconds to finish, it worked with ping and when I execute the line in a terminal window it returns immediately:
(traceroute odesk.com > trace.txt;echo 'traceIsDone'>>trace.txt) &
How can I execute that command and immediately after have PHP go to the next line? So not waiting for the shell_exec command to finish?
You should use
popen():It says it forks the command, ie it starts it in a new thread so it doesn’t block your main thread. Therefore I think that’s what you’d want to use.
You can use it pretty much like
fopen()(if you’re familiar with it), usingfgets(),fgetss()andfwrite().popen() in the PHP Manual