Run shell script from php and see complete progress? Run shell script from php and see complete progress? nginx nginx

Run shell script from php and see complete progress?


Here is another approach. It uses redirection to output the results and then file_get_contents() to read the output.

<?phpecho "loaded<br><br>";$cmd = 'npm start';$run = $cmd . ' > result.txt 2> errors.txt';$output = shell_exec($run);$results = file_get_contents('result.txt');if (strlen(file_get_contents('errors.txt')) != 0) {  $results .= file_get_contents('errors.txt');}echo "<pre>$results</pre>";?>


I guess, ob_flush() would work:

    <?phpecho "loaded<br><br>";ob_flush(); // echo shell_exec("cd /var/www/html/..");// rin the shell scrip from header_register_callbackecho '<pre>';ob_flush();// Outputs all the result of shellcommand "ls", and returns// the last output line into $last_line. Stores the return value// of the shell command in $retval.$last_line = system('cd /var/www/html/; npm start', $retval);// Printing additional infoecho '</pre><hr />Last line of the output: ' . $last_line . '<hr />Return value: ' . $retval;?>

But I don't understand why you echo HTML-tags when you run that script on the console... Hope I got you right