使用 tee -a 保留 PHP 的输出

使用 tee -a 保留 PHP 的输出

通常在 Web 服务器模式下运行 PHP 脚本时,会显示以下内容:

$ php -S 0.0.0.0:12345
PHP 5.6.1 Development Server started at Mon Nov 24 14:09:22 2014
Listening on http://0.0.0.0:12345
Document root is /tmp
Press Ctrl-C to quit.

但是当该命令附加 时| tee -a accesss.log,该输出丢失:

$ php -S 0.0.0.0:12345 | tee -a access.log
# blank

我应该怎么做才能保持显示输出?

答案1

如果你有GNU 标准缓冲区, 您可以使用:

$ stdbuf -o0 -e0 php -S 0.0.0.0:12345 | tee -a access.log
PHP 5.4.34-0+deb7u1 Development Server started at Mon Nov 24 14:38:33 2014
Listening on http://0.0.0.0:12345
Document root is /home/cuonglm
Press Ctrl-C to quit.

相关内容