Why supervisord does not log my PHP CLI fwrite(STDOUT, "message")?
Albert’s Question:
I have a PHP command line application ( zconsole awswebhookrunner ) run by supervisord.
Supervisord does not log on the files fwrite(STDOUT, "message")
but it does log echo "message"
.
Supervisord config
[program:aws_webhook]
command=/home/(username)/bin/zconsole awswebhookrunner
process_name=%(program_name)s_%(process_num)02d
numprocs=1
directory=/tmp
priority=999
autostart=true
autorestart=true
startretries=100
stopwaitsecs=10
user=(username)
stdout_logfile=/home/(username)/logs/aws_webhook_runner.out.log
stderr_logfile=/home/(username)/logs/aws_webhook_runner.err.log
stdout_logfile_maxbytes=10MB
PHP Code
private function log($message, $type="info")
{
$output=STDIN;
switch ($type) {
case "error":
$output=STDERR;
break;
default:
$output=STDIN;
}
$to_log=date("Y-m-d H:i:s")." ".$message;
fwrite($output,$to_log.PHP_EOL) ;
//echo $to_log.PHP_EOL;
fflush($output);
unset($to_log);
}
Software version
PHP version: 5.3.3
OS: CentOS 6.10
supervisord: 3.3.5
Questions
- Is my
supervisord
setup correct? - Do I have a misunderstood the behavior of
fwrite(STDOUT|STDERR, $message);
? - Why
echo $message;
works if it is sent to STDOUT?
- Configuration wise, I think it is fine. Command-wise, it’s a different question really.
- You are trying to
STDIN
rather thanSTDOUT
.STDIN
is used for inputsupervisord
does not deal with STDIN I think. echo
would print to STDOUT because it is its default behavior.