I have a php file which runs a command on linux using shell_exec()
. This command takes some time to complete and at each stage prints something out. I want php to echo every line that is printed by command at the moment it is printed.
I found out using ob_flush()
and flush()
, it is possible to make such chunked http responses, but I can't echo lines as they are printed, because shell_exec()
waits until the command is finished and then returns the output. This way, lines are being echoed when command terminates all at once.
I believe I should avoid using shell_exec()
for such purpose. How else can I achieve this?