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?

3
  • have you tried implicit flush. php.net/manual/en/function.ob-implicit-flush.php Commented Oct 19, 2018 at 7:17
  • thanks buddy, I actually want to implement the tail -f command on the php page. Commented Oct 19, 2018 at 7:22
  • I'm pretty sure it was a combination of system and streaming output. Commented Oct 19, 2018 at 7:30

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks guy, popen method resolved my problem. It exec the command in a stream.
Kool, glad I could help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.