docker 里面的 PHP 应用程序的日志如何输出标准输出(STDOUT)?
问题:docker 里面的 PHP 应用程序的日志如何输出标准输出(STDOUT)?
— 注:不是 php-fpm 的日志
环境:PHP 版本 7.1.13
测试 1:demo 程序如下:
$message = json_encode(array("key1"=>"message1","key2"=>"message2"),true);
$fp = @fopen('php://stdout','w');
fwrite($fp, $message);
fclose($fp);
在 docker 里面执行 php stdout.php 有输出,如下:
通过浏览器访问 stdout.php 文件,只有 nginx 的 access.log 日志,并没有输出上面的 json 信息
PHP 配置文件 /etc/php/7.1/fpm/pool.d/www.conf 也改成
catch_workers_output = yes;
测试 2:
$message = json_encode(array("key1"=>"message1","key2"=>"message2"),true);
file_put_contents('/data/www/stdout.log', $message,FILE_APPEND);
把 stdout.log 重定向的 /dev/stdout
ln -sf /data/www/stdout.log /dev/stdout 也是不行
请求社区大神们怎么解决此问题。
推荐文章: