Index: trunk/php/wmerrors/wmerrors.c |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | #include "php_wmerrors.h" |
11 | 11 | #include "php_streams.h" /* for __php_stream_call_depth */ |
12 | 12 | #include "SAPI.h" /* for sapi_module */ |
| 13 | +#include "ext/standard/file.h" /* for file_globals aka. FG() */ |
13 | 14 | #include "ext/date/php_date.h" /* for php_format_date */ |
14 | 15 | #include "ext/standard/php_smart_str.h" /* for smart_str */ |
15 | 16 | #include "ext/standard/html.h" /* for php_escape_html_entities */ |
— | — | @@ -121,7 +122,6 @@ |
122 | 123 | * it's not enabled, |
123 | 124 | * OR the error is not one of E_{,CORE_,COMPILE_,USER_,RECOVERABLE_}ERROR, |
124 | 125 | * OR the error is an E_RECOVERABLE_ERROR and is being thrown as an exception, |
125 | | - * OR our SAPI is not apache |
126 | 126 | * OR it's triggering itself (recursion guard) |
127 | 127 | */ |
128 | 128 | if ( !WMERRORS_G(enabled) |
— | — | @@ -137,6 +137,7 @@ |
138 | 138 | /* No more OOM errors for now thanks */ |
139 | 139 | zend_set_memory_limit((size_t)-1); |
140 | 140 | |
| 141 | + /* Do not show the html error to console */ |
141 | 142 | if ( WMERRORS_G(enabled) && strncmp(sapi_module.name, "cli", 3) ) { |
142 | 143 | /* Show the message */ |
143 | 144 | wmerrors_show_message(type, error_filename, error_lineno, format, args TSRMLS_CC); |
— | — | @@ -154,6 +155,29 @@ |
155 | 156 | old_error_cb(type, error_filename, error_lineno, format, args); |
156 | 157 | } |
157 | 158 | |
| 159 | +static php_stream * open_logging_file(const char* stream_name) { |
| 160 | + php_stream * stream; |
| 161 | + int err; char *errstr = NULL; |
| 162 | + struct timeval tv; |
| 163 | + |
| 164 | + if ( strncmp( stream_name, "tcp://", 6 ) ) { |
| 165 | + /* Is it a wrapper? */ |
| 166 | + stream = php_stream_open_wrapper(stream_name, "ab", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); |
| 167 | + } else { |
| 168 | + /* Maybe it's a transport? */ |
| 169 | + double timeout = FG(default_socket_timeout); |
| 170 | + unsigned long conv; |
| 171 | + conv = (unsigned long) (timeout * 1000000.0); |
| 172 | + tv.tv_sec = conv / 1000000; |
| 173 | + tv.tv_usec = conv % 1000000; |
| 174 | + |
| 175 | + stream = php_stream_xport_create(stream_name, strlen(stream_name), ENFORCE_SAFE_MODE | REPORT_ERRORS, |
| 176 | + STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, &tv, NULL, &errstr, &err); |
| 177 | + } |
| 178 | + |
| 179 | + return stream; |
| 180 | +} |
| 181 | + |
158 | 182 | /* Callback for zend_print_zval_r_ex() |
159 | 183 | * Gets the file to write from the module global logfile_stream. |
160 | 184 | */ |
— | — | @@ -177,7 +201,7 @@ |
178 | 202 | } |
179 | 203 | |
180 | 204 | /* Try opening the logging file */ |
181 | | - WMERRORS_G(logfile_stream) = php_stream_open_wrapper(WMERRORS_G(logging_file), "ab", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); |
| 205 | + WMERRORS_G(logfile_stream) = open_logging_file( WMERRORS_G(logging_file) ); |
182 | 206 | if ( !WMERRORS_G(logfile_stream) ) { |
183 | 207 | return; |
184 | 208 | } |