Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11316 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48375 invoked by uid 1010); 18 Jul 2004 00:10:41 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 48309 invoked from network); 18 Jul 2004 00:10:41 -0000 Received: from unknown (HELO geburtsjahr.neunzehnhunderteinundachtzig.de) (217.160.92.50) by pb1.pair.com with SMTP; 18 Jul 2004 00:10:41 -0000 Received: from bauernhof (p54802F90.dip.t-dialin.net [84.128.47.144]) by geburtsjahr.neunzehnhunderteinundachtzig.de (Postfix) with ESMTP id 99D868FBE7 for ; Sun, 18 Jul 2004 02:10:46 +0200 (CEST) Received: from faulturm (unknown [192.168.1.4]) by bauernhof (Postfix) with ESMTP id 0377C63151 for ; Sun, 18 Jul 2004 02:10:19 +0200 (CEST) To: internals@lists.php.net Date: Sun, 18 Jul 2004 02:10:08 +0200 User-Agent: KMail/1.6 MIME-Version: 1.0 Content-Disposition: inline Content-Type: Multipart/Mixed; boundary="Boundary-00=_g/b+AnhCyTZmOK+" Message-ID: <200407180210.09034@schlueters.de> Subject: [PATCH] Send errors to stderr instead of stdout From: johannes@php.net (Johannes Schlueter) --Boundary-00=_g/b+AnhCyTZmOK+ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, while developping some shell scripts with PHP-cli I've got annoyed that PHP sends its error messages to STDOUT instead of STDERR so I've written the attached patch. I see two possible problems with this patch where I'm not sure if one of the is really critical: - it uses the PHP STDERR constant defined by PHP-cli. If one doesn't use PHP-cli and defines a constant with this name which is not a stream-resource PHP segfaults. (How do I check wether a resource is a stream-resource?) - there are a few tests checking for error messages and at least ext/standard/tests/file/userstreams.phpt failed for me after applying this patch but other tests testing for error messages worked and I'm not sure why they behave different. (some I/O-Buffers?) The patch was developped and tested on my i686-pc-linux-gnu box against HEAD. johannes PS: The PHP version of HEAD is still 5.0.1-dev but should be 5.1.0-dev, since 5.0.1 is afaik developped in the PHP_5_0 branch. I also added a patch to update these numbers. --Boundary-00=_g/b+AnhCyTZmOK+ Content-Type: text/plain; charset="us-ascii"; name="change_version_numbers.diff.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="change_version_numbers.diff.txt" Index: main/php_version.h =================================================================== RCS file: /repository/php-src/main/php_version.h,v retrieving revision 1.97 diff -u -r1.97 php_version.h --- main/php_version.h 13 Jul 2004 19:56:49 -0000 1.97 +++ main/php_version.h 17 Jul 2004 23:22:22 -0000 @@ -1,7 +1,7 @@ /* automatically generated by configure */ /* edit configure.in to change version number */ #define PHP_MAJOR_VERSION 5 -#define PHP_MINOR_VERSION 0 -#define PHP_RELEASE_VERSION 1 +#define PHP_MINOR_VERSION 1 +#define PHP_RELEASE_VERSION 0 #define PHP_EXTRA_VERSION "-dev" -#define PHP_VERSION "5.0.1-dev" +#define PHP_VERSION "5.1.0-dev" Index: configure.in =================================================================== RCS file: /repository/php-src/configure.in,v retrieving revision 1.514 diff -u -r1.514 configure.in --- configure.in 13 Jul 2004 19:56:48 -0000 1.514 +++ configure.in 17 Jul 2004 23:22:23 -0000 @@ -39,8 +39,8 @@ AC_CONFIG_HEADER(main/php_config.h) MAJOR_VERSION=5 -MINOR_VERSION=0 -RELEASE_VERSION=1 +MINOR_VERSION=1 +RELEASE_VERSION=0 EXTRA_VERSION="-dev" VERSION="$MAJOR_VERSION.$MINOR_VERSION.$RELEASE_VERSION$EXTRA_VERSION" Index: Zend/zend.h =================================================================== RCS file: /repository/ZendEngine2/zend.h,v retrieving revision 1.257 diff -u -r1.257 zend.h --- Zend/zend.h 13 Jul 2004 19:56:49 -0000 1.257 +++ Zend/zend.h 17 Jul 2004 23:22:24 -0000 @@ -22,7 +22,7 @@ #ifndef ZEND_H #define ZEND_H -#define ZEND_VERSION "2.0.1-dev" +#define ZEND_VERSION "2.1.0-dev" #define ZEND_ENGINE_2 --Boundary-00=_g/b+AnhCyTZmOK+ Content-Type: text/plain; charset="us-ascii"; name="errors_to_stderr.diff.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="errors_to_stderr.diff.txt" Index: main/main.c =================================================================== RCS file: /repository/php-src/main/main.c,v retrieving revision 1.605 diff -u -r1.605 main.c --- main/main.c 15 Jul 2004 22:22:06 -0000 1.605 +++ main/main.c 18 Jul 2004 00:01:36 -0000 @@ -735,7 +735,25 @@ char *error_format = PG(html_errors) ? "%s
\n%s: %s in %s on line %d
\n%s" : "%s\n%s: %s in %s on line %d\n%s"; - php_printf(error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + zval *z_stderr = emalloc(sizeof(zval)); + + if (zend_get_constant("STDERR", sizeof("STDERR")-1, z_stderr TSRMLS_DC) && IS_RESOURCE == Z_TYPE_P(z_stderr)) { + php_stream *err_stream; + char *error_msg; + int msg_len; + zval *return_value; /* php_stream_from_zval needs this */ + + php_stream_from_zval(err_stream, &z_stderr); + + msg_len = spprintf(&error_msg, 0, error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + php_stream_write(err_stream, error_msg, msg_len); + + efree(error_msg); + } else { + php_printf(error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + } + + efree(z_stderr); } } #if ZEND_DEBUG --Boundary-00=_g/b+AnhCyTZmOK+--