cvs: php4 /ext/standard output.c php_output.h /main main.c
| From: | Zeev Suraski | Date: | Thu, 23 Nov 2000 18:43:19 +0000 |
| Subject: | cvs: php4 /ext/standard output.c php_output.h /main main.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-2781@lists.php.net to get a copy of this message | ||
zeev Thu Nov 23 10:43:19 2000 EDT
Modified files:
/php4/ext/standard output.c php_output.h
/php4/main main.c
Log:
Very initial work on chunked output buffering. It's really unoptimized at
this time, and it can crash under some circumstances, but that's the
concept...
Index: php4/ext/standard/output.c
diff -u php4/ext/standard/output.c:1.36 php4/ext/standard/output.c:1.37
--- php4/ext/standard/output.c:1.36 Sun Nov 12 14:13:35 2000
+++ php4/ext/standard/output.c Thu Nov 23 10:43:18 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: output.c,v 1.36 2000/11/12 22:13:35 kk Exp $ */
+/* $Id: output.c,v 1.37 2000/11/23 18:43:18 zeev Exp $ */
#include "php.h"
#include "ext/standard/head.h"
@@ -30,7 +30,7 @@
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);
@@ -88,14 +88,14 @@
}
/* 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;
}
@@ -228,7 +228,7 @@
}
-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();
@@ -244,6 +244,7 @@
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;
}
@@ -251,11 +252,27 @@
{
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);
@@ -396,6 +413,7 @@
PHP_FUNCTION(ob_start)
{
zval *output_handler;
+ int chunk_size=0;
switch (ZEND_NUM_ARGS()) {
case 0:
@@ -412,11 +430,24 @@
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;
}
Index: php4/ext/standard/php_output.h
diff -u php4/ext/standard/php_output.h:1.15 php4/ext/standard/php_output.h:1.16
--- php4/ext/standard/php_output.h:1.15 Sat Sep 2 11:03:58 2000
+++ php4/ext/standard/php_output.h Thu Nov 23 10:43:18 2000
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_output.h,v 1.15 2000/09/02 18:03:58 zeev Exp $ */
+/* $Id: php_output.h,v 1.16 2000/11/23 18:43:18 zeev Exp $ */
#ifndef PHP_OUTPUT_H
#define PHP_OUTPUT_H
@@ -26,7 +26,7 @@
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);
@@ -51,6 +51,7 @@
uint text_length;
int block_size;
zval *output_handler;
+ int chunk_size;
} php_ob_buffer;
typedef struct _php_output_globals {
Index: php4/main/main.c
diff -u php4/main/main.c:1.341 php4/main/main.c:1.342
--- php4/main/main.c:1.341 Tue Nov 21 20:23:26 2000
+++ php4/main/main.c Thu Nov 23 10:43:18 2000
@@ -19,7 +19,7 @@
*/
-/* $Id: main.c,v 1.341 2000/11/22 04:23:26 sas Exp $ */
+/* $Id: main.c,v 1.342 2000/11/23 18:43:18 zeev Exp $ */
#include <stdio.h>
@@ -632,9 +632,9 @@
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();
}