api - PHP wait for exec to finish and output the result -


i have php file takes in couple parameters url , runs exec command, in want wait , have results of exec displayed. exec command takes 20-30 seconds finish. never completes because webpage gets nginx 502 bad gateway error (times out).. instead of extending nginx timeout error, that's bad practice have connection hang long, how can run php's exec in , have returned on page after it's complete? or there better way accomplish without using php?

have php trigger exec script forked runs in background (ends &). page should return js periodically polls server via ajax requests check original script's status. script should output stdout , stderr unique file(s) polling script can check status.

edit: if need know script's exit code wrap in script:

#/bin/bash uniqid=$1 yourscript $uniqid & mypid=$! echo $mypid > $uniqid'.pid' wait $mypid echo $? > $uniqid'.returned' 

call ./wrapper.sh someiduniquetoclient &. untested, gist.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -