I have a bash script that is execute in a function in a laravel Controller and I want to output the echos from within while the script is being executed. I tried this way but it does not work, it shows everything togheter after the script is executed.
This is the controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use File;
use Process;
use ProcessFailedException;
class DeployController extends Controller
{
//
public function execute_bash(command)
{
flush();
$fp = popen(command, "r");
while(!feof($fp))
{
// send the current file part to the browser
print fread($fp, 1024);
// flush the content to the browser
flush();
}
fclose($fp);
}
I do that with ajax
$.ajax({
data: parameters,
url: '/executeBash',
type: 'get',
beforeSend: function(){
console.log("executing...");
},
success: function(response){
console.log("success: %O", response);
},
error: function(response){
console.log("error: %O", response);
}
});
This is my Route sentence in web.php Laravel route file called by the ajax function
Route::get('/executeBash', 'DeployController@execute_bash');
command parameter in execute_bash function is a path to the .sh script that inside do some stuff and for any stuff it do, it print an output with echo.
Now, the .sh script is being executed right, but all the outputs (echo) is showed after it finish
How can I achieve wath I want? Thanks!