Page MenuHomePhabricator

dumpBackup.php stderr sent to stdout
Closed, ResolvedPublic


All seems well:
$ php dumpBackup.php --current > backup.xml

Until one day one looks inside:
$ cat backup.xml
DB connection error: Unknown MySQL server host '' (1) (

Therefore, please make sure stderr stuff goes to stderr, and not

(Yes, one can still do php dumpBackup.php||echo 1>&2 FAILED)

Version: 1.12.x
Severity: minor



Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 10:00 PM
bzimport set Reference to bz12184.
bzimport added a subscriber: Unknown Object (MLST).

PHP spews errors to stdout by default. It may be possible to redirect it to stderr, though...

Ok, made changes on two fronts in r28222:

First, the exception reporting has been updated to send output to stderr when in command-line mode. This takes care of database connection errors and various other reportage from MediaWiki code that's done with exceptions.

Second, the setup checks if 'display_errors' is on and, for PHP 5.2.4 or later, switches it to the 'stderr' setting instead. This will cause PHP warnings and errors to also be sent to stderr instead of the stdout stream. However it won't apply to errors which occur before that point in setup is reached, nor will it have any affect on older versions of PHP.

I also tweaked and dumpTextPass to use the stderr mode, which will just disable for older versions of PHP (eg, same as the old behavior setting to false).

As of PHP 5.2.4:

  • Changed "display_errors" php.ini option to accept "stderr" as value which makes the error messages to be outputted to STDERR instead of STDOUT with CGI and CLI SAPIs (FR #22839). (Jani)