summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2001-03-06 15:54:49 +0000
committerZeev Suraski <zeev@php.net>2001-03-06 15:54:49 +0000
commit13a97fefeb0ca24813e6646a943cf1f52849c257 (patch)
tree9be7158e08377010effa1505c42f0f000095dbd7
parent9e43c351586b76b8d4368c5751524aa91399edff (diff)
downloadphp-git-13a97fefeb0ca24813e6646a943cf1f52849c257.tar.gz
Initial work on internal output handlers - should be much quicker
-rw-r--r--ext/standard/output.c47
-rw-r--r--ext/standard/php_output.h8
-rw-r--r--main/output.c47
-rw-r--r--main/php_output.h8
4 files changed, 86 insertions, 24 deletions
diff --git a/ext/standard/output.c b/ext/standard/output.c
index 6f2ad8140e..02c8575617 100644
--- a/ext/standard/output.c
+++ b/ext/standard/output.c
@@ -123,14 +123,29 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
int final_buffer_length=0;
zval *alternate_buffer=NULL;
char *to_be_destroyed_buffer;
+ char *internal_output_handler_buffer;
+ int status;
SLS_FETCH();
OLS_FETCH();
if (OG(nesting_level)==0) {
return;
}
+ status = 0;
+ if (!OG(active_ob_buffer).status & PHP_OUTPUT_HANDLER_START) {
+ /* our first call */
+ status |= PHP_OUTPUT_HANDLER_START;
+ }
+ if (just_flush) {
+ status |= PHP_OUTPUT_HANDLER_CONT;
+ } else {
+ status |= PHP_OUTPUT_HANDLER_END;
+ }
- if (OG(active_ob_buffer).output_handler) {
+ if (OG(active_ob_buffer).internal_output_handler) {
+ internal_output_handler_buffer = OG(active_ob_buffer).internal_output_handler_buffer;
+ OG(active_ob_buffer).internal_output_handler(OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, &internal_output_handler_buffer, status);
+ } else if (OG(active_ob_buffer).output_handler) {
zval **params[2];
zval *orig_buffer;
zval *z_status;
@@ -144,16 +159,7 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
ALLOC_INIT_ZVAL(z_status);
Z_TYPE_P(z_status) = IS_LONG;
- Z_LVAL_P(z_status) = 0;
- if (!OG(active_ob_buffer).status & PHP_OUTPUT_HANDLER_START) {
- /* our first call */
- Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_START;
- }
- if (just_flush) {
- Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_CONT;
- } else {
- Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_END;
- }
+ Z_LVAL_P(z_status) = status;
params[0] = &orig_buffer;
params[1] = &z_status;
@@ -218,6 +224,10 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
OG(active_ob_buffer).status |= PHP_OUTPUT_HANDLER_START;
OG(php_body_write) = php_b_body_write;
}
+ if (OG(active_ob_buffer).internal_output_handler
+ && (internal_output_handler_buffer != OG(active_ob_buffer).internal_output_handler_buffer)) {
+ efree(internal_output_handler_buffer);
+ }
}
@@ -249,6 +259,20 @@ PHPAPI void php_end_implicit_flush()
}
+PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size)
+{
+ OLS_FETCH();
+
+ if (OG(nesting_level)==0) {
+ return;
+ }
+
+ OG(active_ob_buffer).internal_output_handler = internal_output_handler;
+ OG(active_ob_buffer).internal_output_handler_buffer = (char *) emalloc(buffer_size);
+ OG(active_ob_buffer).internal_output_handler_buffer_size = buffer_size;
+}
+
+
/*
* Output buffering - implementation
*/
@@ -285,6 +309,7 @@ static void php_ob_init(uint initial_size, uint block_size, zval *output_handler
OG(active_ob_buffer).output_handler = output_handler;
OG(active_ob_buffer).chunk_size = chunk_size;
OG(active_ob_buffer).status = 0;
+ OG(active_ob_buffer).internal_output_handler = NULL;
}
diff --git a/ext/standard/php_output.h b/ext/standard/php_output.h
index 1792d20257..0cb8647690 100644
--- a/ext/standard/php_output.h
+++ b/ext/standard/php_output.h
@@ -23,6 +23,8 @@
#include "php.h"
+typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, int status);
+
PHPAPI void php_output_startup(void);
void php_output_register_constants(void);
PHPAPI int php_body_write(const char *str, uint str_length);
@@ -36,6 +38,7 @@ PHPAPI void php_start_implicit_flush(void);
PHPAPI void php_end_implicit_flush(void);
PHPAPI char *php_get_output_start_filename(void);
PHPAPI int php_get_output_start_lineno(void);
+PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size);
PHP_FUNCTION(ob_start);
PHP_FUNCTION(ob_end_flush);
@@ -51,9 +54,12 @@ typedef struct _php_ob_buffer {
uint size;
uint text_length;
int block_size;
- zval *output_handler;
uint chunk_size;
int status;
+ zval *output_handler;
+ php_output_handler_func_t internal_output_handler;
+ char *internal_output_handler_buffer;
+ uint internal_output_handler_buffer_size;
} php_ob_buffer;
typedef struct _php_output_globals {
diff --git a/main/output.c b/main/output.c
index 6f2ad8140e..02c8575617 100644
--- a/main/output.c
+++ b/main/output.c
@@ -123,14 +123,29 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
int final_buffer_length=0;
zval *alternate_buffer=NULL;
char *to_be_destroyed_buffer;
+ char *internal_output_handler_buffer;
+ int status;
SLS_FETCH();
OLS_FETCH();
if (OG(nesting_level)==0) {
return;
}
+ status = 0;
+ if (!OG(active_ob_buffer).status & PHP_OUTPUT_HANDLER_START) {
+ /* our first call */
+ status |= PHP_OUTPUT_HANDLER_START;
+ }
+ if (just_flush) {
+ status |= PHP_OUTPUT_HANDLER_CONT;
+ } else {
+ status |= PHP_OUTPUT_HANDLER_END;
+ }
- if (OG(active_ob_buffer).output_handler) {
+ if (OG(active_ob_buffer).internal_output_handler) {
+ internal_output_handler_buffer = OG(active_ob_buffer).internal_output_handler_buffer;
+ OG(active_ob_buffer).internal_output_handler(OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length, &internal_output_handler_buffer, status);
+ } else if (OG(active_ob_buffer).output_handler) {
zval **params[2];
zval *orig_buffer;
zval *z_status;
@@ -144,16 +159,7 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
ALLOC_INIT_ZVAL(z_status);
Z_TYPE_P(z_status) = IS_LONG;
- Z_LVAL_P(z_status) = 0;
- if (!OG(active_ob_buffer).status & PHP_OUTPUT_HANDLER_START) {
- /* our first call */
- Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_START;
- }
- if (just_flush) {
- Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_CONT;
- } else {
- Z_LVAL_P(z_status) |= PHP_OUTPUT_HANDLER_END;
- }
+ Z_LVAL_P(z_status) = status;
params[0] = &orig_buffer;
params[1] = &z_status;
@@ -218,6 +224,10 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush)
OG(active_ob_buffer).status |= PHP_OUTPUT_HANDLER_START;
OG(php_body_write) = php_b_body_write;
}
+ if (OG(active_ob_buffer).internal_output_handler
+ && (internal_output_handler_buffer != OG(active_ob_buffer).internal_output_handler_buffer)) {
+ efree(internal_output_handler_buffer);
+ }
}
@@ -249,6 +259,20 @@ PHPAPI void php_end_implicit_flush()
}
+PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size)
+{
+ OLS_FETCH();
+
+ if (OG(nesting_level)==0) {
+ return;
+ }
+
+ OG(active_ob_buffer).internal_output_handler = internal_output_handler;
+ OG(active_ob_buffer).internal_output_handler_buffer = (char *) emalloc(buffer_size);
+ OG(active_ob_buffer).internal_output_handler_buffer_size = buffer_size;
+}
+
+
/*
* Output buffering - implementation
*/
@@ -285,6 +309,7 @@ static void php_ob_init(uint initial_size, uint block_size, zval *output_handler
OG(active_ob_buffer).output_handler = output_handler;
OG(active_ob_buffer).chunk_size = chunk_size;
OG(active_ob_buffer).status = 0;
+ OG(active_ob_buffer).internal_output_handler = NULL;
}
diff --git a/main/php_output.h b/main/php_output.h
index 1792d20257..0cb8647690 100644
--- a/main/php_output.h
+++ b/main/php_output.h
@@ -23,6 +23,8 @@
#include "php.h"
+typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, int status);
+
PHPAPI void php_output_startup(void);
void php_output_register_constants(void);
PHPAPI int php_body_write(const char *str, uint str_length);
@@ -36,6 +38,7 @@ PHPAPI void php_start_implicit_flush(void);
PHPAPI void php_end_implicit_flush(void);
PHPAPI char *php_get_output_start_filename(void);
PHPAPI int php_get_output_start_lineno(void);
+PHPAPI void php_ob_set_internal_handler(php_output_handler_func_t internal_output_handler, uint buffer_size);
PHP_FUNCTION(ob_start);
PHP_FUNCTION(ob_end_flush);
@@ -51,9 +54,12 @@ typedef struct _php_ob_buffer {
uint size;
uint text_length;
int block_size;
- zval *output_handler;
uint chunk_size;
int status;
+ zval *output_handler;
+ php_output_handler_func_t internal_output_handler;
+ char *internal_output_handler_buffer;
+ uint internal_output_handler_buffer_size;
} php_ob_buffer;
typedef struct _php_output_globals {