2
I have a file .php
where I connect via SSH to a server, and execute commands through it. My file is basically this:
$conexao(servidor,usuario,senha,PORTA);
$ssh->exec('COMANDO 1');
echo'SUCESSO AO EXECUTAR COMANDO 1';
$ssh->exec('COMANDO 2');
echo'SUCESSO AO EXECUTAR COMANDO 2';
$ssh->exec('COMANDO 3');
echo'SUCESSO AO EXECUTAR COMANDO 3';
It normally runs the commands, no errors, but PHP runs all the commands, and only after that shows the output of the commands echo
, all at once.
I wanted to when executing the COMANDO1
, was shown just below the output of the echo
, informing that the command worked, and then go to the next command and so on.
In the example I mentioned echo as echo 'Success'; only that my real echo is echo '<span class="txtsucesso">Success</span>'; a span with a style, to make the text more beautiful, would have a problem?
– Paulo Previatto
The "problem" is that
<span>
will not be interpreted as HTML, but as any text. If you need to handle this response from the server, you will need some Javascript, such as usingEventSource
.– Andre
Unfortunately I don’t have the tools to test here, but try to delete the header
Content-Type: text/event-stream
and make sure it still works, maybe that’s enough to interpret the answer as an HTML. I can’t guarantee it will work.– Andre
@Paulo, PHP sends as you do
echo
, is the browser that caches to display only at the end. How are you making this request? You are using a simple redirect, or using AJAX?– Andre
I was able to make the pieces appear in order, but I had to add a code after the headers which is "ob_end_flush();" what he does?
– Paulo Previatto
And yes, by removing "header('Content-Type: text/Event-stream');" I can easily use html elements in echo
– Paulo Previatto