0

I want to output log file on the php page, including upcoming content.

Like this, but is not allowed by php.

header('Content-Type: text/plain;');
flush();
exec('docker logs server --follow', 'php://output'); // Follow log output

What's the best practice to continue executing output commands in a long time?

joaner
  • 706
  • 1
  • 5
  • 17

1 Answers1

0

I don't know if it will work but I would try something like this:

// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);
// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
ob_implicit_flush(true);
// Clear, and turn off output buffering
while (ob_get_level() > 0) ob_end_clean();
system('docker logs server --follow');

system directly sends output to the buffer, and ob_implicit_flush will do a flush whenever output is sent. You may have to turn of gzip, and someother things.

I did do a -tail once for a server log, but it was years ago so I can't remember how I did it. It was in an iFrame, so I could display it on a web page. I remember that.

ArtisticPhoenix
  • 21,464
  • 2
  • 24
  • 38