static int php_ub_body_write_no_header(const char *str, uint str_length);
static int php_b_body_write(const char *str, uint str_length);
-static void php_ob_init(uint initial_size, uint block_size, zval *output_handler);
+static void php_ob_init(uint initial_size, uint block_size, zval *output_handler, int chunk_size);
static void php_ob_append(const char *text, uint text_length);
#if 0
static void php_ob_prepend(const char *text, uint text_length);
}
/* Start output buffering */
-PHPAPI int php_start_ob_buffer(zval *output_handler)
+PHPAPI int php_start_ob_buffer(zval *output_handler, int chunk_size)
{
OLS_FETCH();
if (OG(lock)) {
return FAILURE;
}
- php_ob_init(40*1024, 10*1024, output_handler);
+ php_ob_init(40*1024, 10*1024, output_handler, chunk_size);
OG(php_body_write) = php_b_body_write;
return SUCCESS;
}
}
-static void php_ob_init(uint initial_size, uint block_size, zval *output_handler)
+static void php_ob_init(uint initial_size, uint block_size, zval *output_handler, int chunk_size)
{
OLS_FETCH();
OG(active_ob_buffer).buffer = (char *) emalloc(initial_size+1);
OG(active_ob_buffer).text_length = 0;
OG(active_ob_buffer).output_handler = output_handler;
+ OG(active_ob_buffer).chunk_size = chunk_size;
}
{
char *target;
int original_ob_text_length;
+ int new_size;
OLS_FETCH();
original_ob_text_length=OG(active_ob_buffer).text_length;
- OG(active_ob_buffer).text_length += text_length;
+ new_size = OG(active_ob_buffer).text_length + text_length;
+
+ if (OG(active_ob_buffer).chunk_size
+ && new_size > OG(active_ob_buffer).chunk_size) {
+ zval *output_handler = OG(active_ob_buffer).output_handler;
+ int chunk_size = OG(active_ob_buffer).chunk_size;
+
+ if (output_handler) {
+ output_handler->refcount++;
+ }
+ php_end_ob_buffer(1);
+ php_start_ob_buffer(output_handler, chunk_size);
+ php_ob_append(text, text_length);
+ return;
+ }
+ OG(active_ob_buffer).text_length = new_size;
php_ob_allocate();
target = OG(active_ob_buffer).buffer+original_ob_text_length;
memcpy(target, text, text_length);
PHP_FUNCTION(ob_start)
{
zval *output_handler;
+ int chunk_size=0;
switch (ZEND_NUM_ARGS()) {
case 0:
output_handler->refcount++;
}
break;
+ case 2: {
+ zval **output_handler_p, **chunk_size_p;
+
+ if (zend_get_parameters_ex(2, &output_handler_p, &chunk_size_p)==FAILURE) {
+ RETURN_FALSE;
+ }
+ SEPARATE_ZVAL(output_handler_p);
+ output_handler = *output_handler_p;
+ output_handler->refcount++;
+ convert_to_long_ex(chunk_size_p);
+ chunk_size = Z_LVAL_PP(chunk_size_p);
+ }
+ break;
default:
ZEND_WRONG_PARAM_COUNT();
break;
}
- if (php_start_ob_buffer(output_handler)==FAILURE) {
+ if (php_start_ob_buffer(output_handler, chunk_size)==FAILURE) {
php_error(E_WARNING, "Cannot use output buffering in output buffering display handlers");
RETURN_FALSE;
}
PHPAPI void php_output_startup(void);
PHPAPI int php_body_write(const char *str, uint str_length);
PHPAPI int php_header_write(const char *str, uint str_length);
-PHPAPI int php_start_ob_buffer(zval *output_handler);
+PHPAPI int php_start_ob_buffer(zval *output_handler, int chunk_size);
PHPAPI void php_end_ob_buffer(int send_buffer);
PHPAPI void php_end_ob_buffers(int send_buffer);
PHPAPI int php_ob_get_buffer(pval *p);
uint text_length;
int block_size;
zval *output_handler;
+ int chunk_size;
} php_ob_buffer;
typedef struct _php_output_globals {
Z_STRLEN_P(output_handler) = strlen(PG(output_handler)); /* this can be optimized */
Z_STRVAL_P(output_handler) = estrndup(PG(output_handler), Z_STRLEN_P(output_handler));
Z_TYPE_P(output_handler) = IS_STRING;
- php_start_ob_buffer(output_handler);
+ php_start_ob_buffer(output_handler, 0);
} else if (PG(output_buffering)) {
- php_start_ob_buffer(NULL);
+ php_start_ob_buffer(NULL, 0);
} else if (PG(implicit_flush)) {
php_start_implicit_flush();
}
static int php_ub_body_write_no_header(const char *str, uint str_length);
static int php_b_body_write(const char *str, uint str_length);
-static void php_ob_init(uint initial_size, uint block_size, zval *output_handler);
+static void php_ob_init(uint initial_size, uint block_size, zval *output_handler, int chunk_size);
static void php_ob_append(const char *text, uint text_length);
#if 0
static void php_ob_prepend(const char *text, uint text_length);
}
/* Start output buffering */
-PHPAPI int php_start_ob_buffer(zval *output_handler)
+PHPAPI int php_start_ob_buffer(zval *output_handler, int chunk_size)
{
OLS_FETCH();
if (OG(lock)) {
return FAILURE;
}
- php_ob_init(40*1024, 10*1024, output_handler);
+ php_ob_init(40*1024, 10*1024, output_handler, chunk_size);
OG(php_body_write) = php_b_body_write;
return SUCCESS;
}
}
-static void php_ob_init(uint initial_size, uint block_size, zval *output_handler)
+static void php_ob_init(uint initial_size, uint block_size, zval *output_handler, int chunk_size)
{
OLS_FETCH();
OG(active_ob_buffer).buffer = (char *) emalloc(initial_size+1);
OG(active_ob_buffer).text_length = 0;
OG(active_ob_buffer).output_handler = output_handler;
+ OG(active_ob_buffer).chunk_size = chunk_size;
}
{
char *target;
int original_ob_text_length;
+ int new_size;
OLS_FETCH();
original_ob_text_length=OG(active_ob_buffer).text_length;
- OG(active_ob_buffer).text_length += text_length;
+ new_size = OG(active_ob_buffer).text_length + text_length;
+
+ if (OG(active_ob_buffer).chunk_size
+ && new_size > OG(active_ob_buffer).chunk_size) {
+ zval *output_handler = OG(active_ob_buffer).output_handler;
+ int chunk_size = OG(active_ob_buffer).chunk_size;
+
+ if (output_handler) {
+ output_handler->refcount++;
+ }
+ php_end_ob_buffer(1);
+ php_start_ob_buffer(output_handler, chunk_size);
+ php_ob_append(text, text_length);
+ return;
+ }
+ OG(active_ob_buffer).text_length = new_size;
php_ob_allocate();
target = OG(active_ob_buffer).buffer+original_ob_text_length;
memcpy(target, text, text_length);
PHP_FUNCTION(ob_start)
{
zval *output_handler;
+ int chunk_size=0;
switch (ZEND_NUM_ARGS()) {
case 0:
output_handler->refcount++;
}
break;
+ case 2: {
+ zval **output_handler_p, **chunk_size_p;
+
+ if (zend_get_parameters_ex(2, &output_handler_p, &chunk_size_p)==FAILURE) {
+ RETURN_FALSE;
+ }
+ SEPARATE_ZVAL(output_handler_p);
+ output_handler = *output_handler_p;
+ output_handler->refcount++;
+ convert_to_long_ex(chunk_size_p);
+ chunk_size = Z_LVAL_PP(chunk_size_p);
+ }
+ break;
default:
ZEND_WRONG_PARAM_COUNT();
break;
}
- if (php_start_ob_buffer(output_handler)==FAILURE) {
+ if (php_start_ob_buffer(output_handler, chunk_size)==FAILURE) {
php_error(E_WARNING, "Cannot use output buffering in output buffering display handlers");
RETURN_FALSE;
}
PHPAPI void php_output_startup(void);
PHPAPI int php_body_write(const char *str, uint str_length);
PHPAPI int php_header_write(const char *str, uint str_length);
-PHPAPI int php_start_ob_buffer(zval *output_handler);
+PHPAPI int php_start_ob_buffer(zval *output_handler, int chunk_size);
PHPAPI void php_end_ob_buffer(int send_buffer);
PHPAPI void php_end_ob_buffers(int send_buffer);
PHPAPI int php_ob_get_buffer(pval *p);
uint text_length;
int block_size;
zval *output_handler;
+ int chunk_size;
} php_ob_buffer;
typedef struct _php_output_globals {