mike                                     Tue, 31 Jan 2012 08:51:24 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=322963

Log:
fix headers print to stdout/stderr if no output written; need to make some more 
testsbefore committing to PHP_5_4; fix crashes and invalid usage of output 
control in cli server while passing by

Changed paths:
    U   php/php-src/trunk/main/main.c
    U   php/php-src/trunk/main/output.c
    U   php/php-src/trunk/sapi/cli/php_cli_server.c

Modified: php/php-src/trunk/main/main.c
===================================================================
--- php/php-src/trunk/main/main.c       2012-01-31 07:17:05 UTC (rev 322962)
+++ php/php-src/trunk/main/main.c       2012-01-31 08:51:24 UTC (rev 322963)
@@ -1738,12 +1738,11 @@
                } else {
                        php_output_end_all(TSRMLS_C);
                }
-               php_output_deactivate(TSRMLS_C);
        } zend_end_try();

-       /* 4. Send the set HTTP headers (note: This must be done AFTER 
php_output_discard_all() / php_output_end_all() !!) */
+       /* 4. Shutdown output layer (send the set HTTP headers, cleanup output 
handlers, etc.) */
        zend_try {
-               sapi_send_headers(TSRMLS_C);
+               php_output_deactivate(TSRMLS_C);
        } zend_end_try();

        /* 5. Reset max_execution_time (no longer executing php code after 
response sent) */

Modified: php/php-src/trunk/main/output.c
===================================================================
--- php/php-src/trunk/main/output.c     2012-01-31 07:17:05 UTC (rev 322962)
+++ php/php-src/trunk/main/output.c     2012-01-31 08:51:24 UTC (rev 322963)
@@ -103,6 +103,29 @@
 static int (*php_output_direct)(const char *str, size_t str_len) = 
php_output_stderr;
 /* }}} */

+/* {{{ void php_output_header(TSRMLS_D) */
+static void php_output_header(TSRMLS_D)
+{
+       if (!SG(headers_sent)) {
+               if (!OG(output_start_filename)) {
+                       if (zend_is_compiling(TSRMLS_C)) {
+                               OG(output_start_filename) = 
zend_get_compiled_filename(TSRMLS_C);
+                               OG(output_start_lineno) = 
zend_get_compiled_lineno(TSRMLS_C);
+                       } else if (zend_is_executing(TSRMLS_C)) {
+                               OG(output_start_filename) = 
zend_get_executed_filename(TSRMLS_C);
+                               OG(output_start_lineno) = 
zend_get_executed_lineno(TSRMLS_C);
+                       }
+#if PHP_OUTPUT_DEBUG
+                       fprintf(stderr, "!!! output started at: %s (%d)\n", 
OG(output_start_filename), OG(output_start_lineno));
+#endif
+               }
+               if (!php_header(TSRMLS_C)) {
+                       OG(flags) |= PHP_OUTPUT_DISABLED;
+               }
+       }
+}
+/* }}} */
+
 /* {{{ void php_output_startup(void)
  * Set up module globals and initalize the conflict and reverse conflict hash 
tables */
 PHPAPI void php_output_startup(void)
@@ -149,6 +172,9 @@
 {
        php_output_handler **handler = NULL;

+       php_output_header(TSRMLS_C);
+
+       OG(flags) ^= PHP_OUTPUT_ACTIVATED;
        OG(active) = NULL;
        OG(running) = NULL;

@@ -161,7 +187,6 @@
                zend_stack_destroy(&OG(handlers));
        }

-       OG(flags) ^= PHP_OUTPUT_ACTIVATED;
 }
 /* }}} */

@@ -1045,26 +1070,20 @@
        }

        if (context.out.data && context.out.used) {
+               php_output_header(TSRMLS_C);
+
+               if (!(OG(flags) & PHP_OUTPUT_DISABLED)) {
 #if PHP_OUTPUT_DEBUG
-               fprintf(stderr, "::: sapi_write('%s', %zu)\n", 
context.out.data, context.out.used);
+                       fprintf(stderr, "::: sapi_write('%s', %zu)\n", 
context.out.data, context.out.used);
 #endif
-               if (!SG(headers_sent) && php_header(TSRMLS_C)) {
-                       if (zend_is_compiling(TSRMLS_C)) {
-                               OG(output_start_filename) = 
zend_get_compiled_filename(TSRMLS_C);
-                               OG(output_start_lineno) = 
zend_get_compiled_lineno(TSRMLS_C);
-                       } else if (zend_is_executing(TSRMLS_C)) {
-                               OG(output_start_filename) = 
zend_get_executed_filename(TSRMLS_C);
-                               OG(output_start_lineno) = 
zend_get_executed_lineno(TSRMLS_C);
+                       sapi_module.ub_write(context.out.data, context.out.used 
TSRMLS_CC);
+
+                       if (OG(flags) & PHP_OUTPUT_IMPLICITFLUSH) {
+                               sapi_flush(TSRMLS_C);
                        }
-#if PHP_OUTPUT_DEBUG
-                       fprintf(stderr, "!!! output started at: %s (%d)\n", 
OG(output_start_filename), OG(output_start_lineno));
-#endif
+
+                       OG(flags) |= PHP_OUTPUT_SENT;
                }
-               sapi_module.ub_write(context.out.data, context.out.used 
TSRMLS_CC);
-               if (OG(flags) & PHP_OUTPUT_IMPLICITFLUSH) {
-                       sapi_flush(TSRMLS_C);
-               }
-               OG(flags) |= PHP_OUTPUT_SENT;
        }
        php_output_context_dtor(&context);
 }

Modified: php/php-src/trunk/sapi/cli/php_cli_server.c
===================================================================
--- php/php-src/trunk/sapi/cli/php_cli_server.c 2012-01-31 07:17:05 UTC (rev 
322962)
+++ php/php-src/trunk/sapi/cli/php_cli_server.c 2012-01-31 08:51:24 UTC (rev 
322963)
@@ -325,6 +325,9 @@

 static void append_http_status_line(smart_str *buffer, int protocol_version, 
int response_code, int persistent) /* {{{ */
 {
+       if (!response_code) {
+               response_code = 200;
+       }
        smart_str_appendl_ex(buffer, "HTTP", 4, persistent);
        smart_str_appendc_ex(buffer, '/', persistent);
        smart_str_append_generic_ex(buffer, protocol_version / 100, persistent, 
int, _unsigned);
@@ -1752,13 +1755,11 @@
                int err = 0;
                zval *style = NULL;
                zend_try {
-                       php_output_activate(TSRMLS_C);
                        php_output_start_user(NULL, 0, 
PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
                        php_info_print_style(TSRMLS_C);
                        MAKE_STD_ZVAL(style);
                        php_output_get_contents(style TSRMLS_CC);
                        php_output_discard(TSRMLS_C);
-                       php_output_deactivate(TSRMLS_C);
                        if (style && Z_STRVAL_P(style)) {
                                char *block = pestrndup(Z_STRVAL_P(style), 
Z_STRLEN_P(style), 1);
                                php_cli_server_chunk *chunk = 
php_cli_server_chunk_heap_new(block, block, Z_STRLEN_P(style));

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to