]> granicus.if.org Git - php/commitdiff
Changed handling of output buffer sizes.
authorMarcus Boerger <helly@php.net>
Tue, 20 Aug 2002 19:49:37 +0000 (19:49 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 20 Aug 2002 19:49:37 +0000 (19:49 +0000)
@Added php.ini option "double_buffering" that forces an additional first
@output buffer and improved handling of buffer sizes. (Marcus)

main/main.c
main/output.c
main/php_globals.h
main/php_output.h

index 97aa91860b0161e54c317c8cfefdbfbb490c2895..311b7ba1a5b7353cff04570ef2c7a4e7d09694f1 100644 (file)
@@ -197,6 +197,24 @@ static PHP_INI_MH(OnUpdateTimeout)
 }
 /* }}} */
 
+/* {{{ OnUpdateOutputBuffering
+ */
+static PHP_INI_MH(OnUpdateOutputBuffering)
+{
+       if(!strncasecmp(new_value, "off", sizeof("off"))) {
+               new_value = "0";
+               new_value_length = sizeof("0");
+       } else if(!strncasecmp(new_value, "on", sizeof("on"))) {
+               new_value = "1";
+               new_value_length = sizeof("1");
+       }
+       OnUpdateInt(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+       
+       return SUCCESS;
+}
+/* }}} */
+
+
 /* Need to convert to strings and make use of:
  * PHP_SAFE_MODE
  *
@@ -249,7 +267,8 @@ PHP_INI_BEGIN()
        STD_PHP_INI_BOOLEAN("magic_quotes_gpc",         "1",            PHP_INI_ALL,            OnUpdateBool,                   magic_quotes_gpc,               php_core_globals,       core_globals)
        STD_PHP_INI_BOOLEAN("magic_quotes_runtime",     "0",            PHP_INI_ALL,            OnUpdateBool,                   magic_quotes_runtime,   php_core_globals,       core_globals)
        STD_PHP_INI_BOOLEAN("magic_quotes_sybase",      "0",            PHP_INI_ALL,            OnUpdateBool,                   magic_quotes_sybase,    php_core_globals,       core_globals)
-       STD_PHP_INI_ENTRY("output_buffering",           "0",            PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateInt,      output_buffering,               php_core_globals,       core_globals)
+       STD_PHP_INI_ENTRY("output_buffering",           "0",            PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateOutputBuffering,  output_buffering,               php_core_globals,       core_globals)
+       STD_PHP_INI_ENTRY("double_buffering",           "0",            PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateOutputBuffering,  double_buffering,               php_core_globals,       core_globals)
        STD_PHP_INI_ENTRY("output_handler",                     NULL,           PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateString,   output_handler,         php_core_globals,       core_globals)
        STD_PHP_INI_BOOLEAN("register_argc_argv",       "1",            PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateBool,     register_argc_argv,             php_core_globals,       core_globals)
        STD_PHP_INI_BOOLEAN("register_globals",         "0",            PHP_INI_PERDIR|PHP_INI_SYSTEM,OnUpdateBool,     register_globals,               php_core_globals,       core_globals)
@@ -826,12 +845,7 @@ int php_request_startup(TSRMLS_D)
                        php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC);
                }
                else if (PG(output_buffering)) {
-                       if (PG(output_buffering)>1) {
-                               php_start_ob_buffer(NULL, PG(output_buffering), 0 TSRMLS_CC);
-                       }
-                       else {
-                               php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
-                       }
+                       php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
                }
                else if (PG(implicit_flush)) {
                        php_start_implicit_flush(TSRMLS_C);
index 5ad6c556f9df7c4920d079975ae712336e66b4a6..113110697288ff8f91d47341ac4fc4fd4c206acb 100644 (file)
@@ -113,23 +113,39 @@ PHPAPI int php_header_write(const char *str, uint str_length TSRMLS_DC)
        }
 }
 
+/* {{{ php_ob_default_buffer_size
+ * Start output buffering */
+PHPAPI int php_ob_default_buffer_size(TSRMLS_D)
+{
+       uint buffer_size = (uint)(PG(output_buffering) > 1 ? PG(output_buffering) : 4096);
+       if (OG(ob_nesting_level)==0 && PG(double_buffering)!=0) {
+               buffer_size = (uint)(PG(double_buffering) >= buffer_size ? PG(double_buffering) : 4*buffer_size);
+       }
+       return buffer_size;
+}
+/* }}} */
+
 /* {{{ php_start_ob_buffer
  * Start output buffering */
 PHPAPI int php_start_ob_buffer(zval *output_handler, uint chunk_size, zend_bool erase TSRMLS_DC)
 {
-       uint initial_size, block_size;
+       uint initial_chunk_size, initial_size, block_size;
 
        if (OG(ob_lock)) {
                php_error_docref("ref.outcontrol" TSRMLS_CC, E_ERROR, "Cannot use output buffering in output buffering display handlers");
                return FAILURE;
        }
-       if (chunk_size) {
-               initial_size = (chunk_size*3/2);
-               block_size = chunk_size/2;
-       } else {
-               initial_size = 40*1024;
-               block_size = 10*1024;
+       if (OG(ob_nesting_level)==0 && PG(double_buffering)) {          
+               initial_chunk_size = php_ob_default_buffer_size(TSRMLS_C);
+               initial_size = 4*initial_chunk_size;
+               block_size = initial_chunk_size;
+               php_ob_init(initial_size, block_size, NULL, initial_chunk_size, erase TSRMLS_CC);
+       }
+       if (chunk_size<2) {
+               chunk_size = php_ob_default_buffer_size(TSRMLS_C);
        }
+       initial_size = chunk_size;
+       block_size = chunk_size;
        return php_ob_init(initial_size, block_size, output_handler, chunk_size, erase TSRMLS_CC);
 }
 /* }}} */
@@ -327,6 +343,9 @@ PHPAPI void php_end_implicit_flush(TSRMLS_D)
  */
 PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size, char *handler_name, zend_bool erase TSRMLS_DC)
 {
+       if (buffer_size<2) {
+               buffer_size = php_ob_default_buffer_size(TSRMLS_C);
+       }
        if (OG(ob_nesting_level)==0 || OG(active_ob_buffer).internal_output_handler || strcmp(OG(active_ob_buffer).handler_name, OB_DEFAULT_HANDLER_NAME)) {
                php_start_ob_buffer(NULL, buffer_size, erase TSRMLS_CC);
        }
@@ -389,6 +408,10 @@ static int php_ob_init_named(uint initial_size, uint block_size, char *handler_n
                        php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler '%s' cannot be used twice", handler_name);
                        return FAILURE;
                }
+               if (!handler_gz && SG(headers_sent)) {
+                       php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "output handler '%s' cannot be activated - headers already sent", handler_name);
+                       return FAILURE;
+               }
                if (!handler_gz && php_ob_init_conflict(handler_name, "zlib output compression" TSRMLS_CC))
                        return FAILURE;
                if (!handler_mb && php_ob_init_conflict(handler_name, "ob_iconv_handler" TSRMLS_CC))
@@ -844,8 +867,8 @@ static int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result)
        else {
                add_assoc_long(elem, "type", PHP_OUTPUT_HANDLER_USER);
                add_assoc_long(elem, "initial_size", ob_buffer->size);
-               add_assoc_long(elem, "chunk_size", ob_buffer->chunk_size);
        }
+       add_assoc_long(elem, "chunk_size", ob_buffer->chunk_size);
        add_assoc_long(elem, "status", ob_buffer->status);
        add_assoc_string(elem, "name", ob_buffer->handler_name, 1);
        add_assoc_bool(elem, "del", ob_buffer->erase);
index 9082a123ea22f0b81204d3e6e8ffa5111cba64ae..10639de0a1644cee9f6fc097f2b6a2531a8d3dfe 100644 (file)
@@ -58,6 +58,7 @@ struct _php_core_globals {
        zend_bool implicit_flush;
 
        int output_buffering;
+       int double_buffering;
 
        char *safe_mode_include_dir;
        zend_bool safe_mode_gid;
index 0c485e834c86e249bf3bff00383e515fa778f926..eb26087a0bae933970a9ff12bffa071645171610 100644 (file)
@@ -41,6 +41,7 @@ PHPAPI char *php_get_output_start_filename(TSRMLS_D);
 PHPAPI int php_get_output_start_lineno(TSRMLS_D);
 PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size, char *handler_name, zend_bool erase TSRMLS_DC);
 PHPAPI int php_ob_handler_used(char *handler_name TSRMLS_DC);
+PHPAPI int php_ob_default_buffer_size(TSRMLS_D);
 
 PHP_FUNCTION(ob_start);
 PHP_FUNCTION(ob_flush);