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 也是不行
请求社区大神们怎么解决此问题。
推荐文章: