diff options
author | Zeev Suraski <zeev@php.net> | 2000-01-13 17:37:25 +0000 |
---|---|---|
committer | Zeev Suraski <zeev@php.net> | 2000-01-13 17:37:25 +0000 |
commit | 972631be7105a3120a405dc0d25c2dbb7179cd13 (patch) | |
tree | fce49aae99b6b0f3f2cd2f80a9a5580ff495fa6b /ext/standard | |
parent | c658fc5cbdede7c8d11c7bf7eb84b342ae34c2e3 (diff) | |
download | php-git-972631be7105a3120a405dc0d25c2dbb7179cd13.tar.gz |
- Added flush() support to SAPI
- Got rid of the old flush() implemenetation in favour of the new one
- Added implicit_flush() support to the output buffering layer.
@- Added implicit_flush() to control whether flush() should be called
@ implicitly after any output (Zeev)
Diffstat (limited to 'ext/standard')
-rw-r--r-- | ext/standard/basic_functions.c | 22 | ||||
-rw-r--r-- | ext/standard/head.c | 159 | ||||
-rw-r--r-- | ext/standard/output.c | 48 | ||||
-rw-r--r-- | ext/standard/php_output.h | 4 |
4 files changed, 43 insertions, 190 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index eee7221c71..a8b1d4dc42 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -595,28 +595,10 @@ PHP_FUNCTION(strval) convert_to_string(return_value); } + PHP_FUNCTION(flush) { -#if APACHE - SLS_FETCH(); -#endif - -#if APACHE -# if MODULE_MAGIC_NUMBER > 19970110 - rflush(((request_rec *) SG(server_context))); -# else - bflush(((request_rec *) SG(server_context))->connection->client); -# endif -#endif -#if FHTTPD - /*FIXME -- what does it flush really? the whole response?*/ -#endif -#if CGI_BINARY - fflush(stdout); -#endif -#if USE_SAPI - sapi_rqst->flush(sapi_rqst->scid); -#endif + sapi_flush(); } diff --git a/ext/standard/head.c b/ext/standard/head.c index 2fa708eda5..a6b973cec6 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -203,163 +203,6 @@ PHP_FUNCTION(Header) } - - - -#if 0 -/* - * php_header() flushes the header info built up using calls to - * the Header() function. If type is 1, a redirect to str is done. - * Otherwise type should be 0 and str NULL. - * - * The function returns non-zero if output is allowed after the - * call, and zero otherwise. Any call to php_header() must check - * the return status and if false, no output must be sent. This - * is in order to correctly handle HEAD requests. - */ -PHPAPI int php_header(void) -{ -#if APACHE - CookieList *cookie; - int len = 0; - time_t t; - char *dt, *cookievalue = NULL; -#endif -#if APACHE || defined(USE_SAPI) || FHTTPD - char *tempstr; -#endif - PLS_FETCH(); - SLS_FETCH(); - - if (PG(header_is_being_sent)) { - return 0; - } else { - PG(header_is_being_sent) = 1; - } - -#if APACHE - if (!((request_rec *) SG(server_context))) { /* we're not in a request, allow output */ - PG(header_is_being_sent) = 0; - return 1; - } - if ((php_print_header && !php_header_printed) || (php_print_header && php_header_printed == 2)) { - cookie = php_pop_cookie_list(); - while (cookie) { - if (cookie->name) - len += strlen(cookie->name); - if (cookie->value) { - cookievalue = php_url_encode(cookie->value, strlen (cookie->value)); - len += strlen(cookievalue); - } - if (cookie->path) - len += strlen(cookie->path); - if (cookie->domain) - len += strlen(cookie->domain); - tempstr = emalloc(len + 100); - if (!cookie->value || (cookie->value && !*cookie->value)) { - /* - * MSIE doesn't delete a cookie when you set it to a null value - * so in order to force cookies to be deleted, even on MSIE, we - * pick an expiry date 1 year and 1 second in the past - */ - sprintf(tempstr, "%s=deleted", cookie->name); - t = time(NULL) - 31536001; - strcat(tempstr, "; expires="); - dt = php_std_date(t); - strcat(tempstr, dt); - efree(dt); - } else { - /* FIXME: XXX: this is not binary data safe */ - sprintf(tempstr, "%s=%s", cookie->name, cookie->value ? cookievalue : ""); - if (cookie->name) efree(cookie->name); - if (cookie->value) efree(cookie->value); - if (cookievalue) efree(cookievalue); - cookie->name=NULL; - cookie->value=NULL; - cookievalue=NULL; - if (cookie->expires > 0) { - strcat(tempstr, "; expires="); - dt = php_std_date(cookie->expires); - strcat(tempstr, dt); - efree(dt); - } - } - if (cookie->path && strlen(cookie->path)) { - strcat(tempstr, "; path="); - strcat(tempstr, cookie->path); - efree(cookie->path); - cookie->path=NULL; - } - if (cookie->domain && strlen(cookie->domain)) { - strcat(tempstr, "; domain="); - strcat(tempstr, cookie->domain); - efree(cookie->domain); - cookie->domain=NULL; - } - if (cookie->secure) { - strcat(tempstr, "; secure"); - } - table_add(((request_rec *) SG(server_context))->headers_out, "Set-Cookie", tempstr); - if (cookie->domain) efree(cookie->domain); - if (cookie->path) efree(cookie->path); - if (cookie->name) efree(cookie->name); - if (cookie->value) efree(cookie->value); - if (cookievalue) efree(cookievalue); - efree(cookie); - cookie = php_pop_cookie_list(); - efree(tempstr); - } - php_header_printed = 1; - header_called = 1; - send_http_header(((request_rec *) SG(server_context))); - if (((request_rec *) SG(server_context))->header_only) { - set_header_request(1); - PG(header_is_being_sent) = 0; - return(0); - } - } -#else - if (php_print_header && !php_header_printed) { - if (!cont_type) { -#if USE_SAPI - sapi_rqst->header(sapi_rqst->scid,"Content-type: text/html\015\012\015\012"); -#else - PUTS_H("Content-type: text/html\015\012\015\012"); -#endif - } else { -#if 0 /*WIN32|WINNT / *M$ does us again*/ - if (!strcmp(cont_type,"text/html")){ -#endif -#if USE_SAPI - tempstr=emalloc(strlen(cont_type)+18); - sprintf(tempstr,"Content-type: %s\015\012\015\012",cont_type); - sapi_rqst->header(sapi_rqst->scid,tempstr); - efree(tempstr); -#else - PUTS_H("Content-type:"); - PUTS_H(cont_type); - PUTS_H("\015\012\015\012"); -#endif - efree(cont_type); -#if 0 /*WIN32|WINNT / *M$ does us again*/ - } else { - PUTS_H("\015\012"); - }/*end excluding output of text/html*/ -#endif - } -#if USE_SAPI - sapi_rqst->flush(sapi_rqst->scid); -#else - fflush(stdout); -#endif - php_header_printed = 1; - header_called = 1; - } -#endif - PG(header_is_being_sent) = 0; - return(1); -} -#else PHPAPI int php_header() { SLS_FETCH(); @@ -370,8 +213,6 @@ PHPAPI int php_header() return 1; /* allow output */ } } -#endif - void php_push_cookie_list(char *name, char *value, time_t expires, char *path, char *domain, int secure) diff --git a/ext/standard/output.c b/ext/standard/output.c index ab5ee333e7..5ba4c92831 100644 --- a/ext/standard/output.c +++ b/ext/standard/output.c @@ -37,12 +37,6 @@ static void php_ob_prepend(const char *text, uint text_length); #endif static inline void php_ob_send(void); -void php_start_ob_buffering(void); -void php_end_ob_buffering(int send_buffer); -int php_ob_get_buffer(pval *p); - -/* HEAD support */ -void set_header_request(int value); typedef struct { int (*php_body_write)(const char *str, uint str_length); /* string output */ @@ -51,6 +45,7 @@ typedef struct { uint ob_size; uint ob_block_size; uint ob_text_length; + unsigned char implicit_flush; } php_output_globals; #ifdef ZTS @@ -82,13 +77,14 @@ static void php_output_init_globals(OLS_D) OG(ob_size) = 0; OG(ob_block_size) = 0; OG(ob_text_length) = 0; + OG(implicit_flush) = 0; } PHP_GINIT_FUNCTION(output) { #ifdef ZTS - output_globals_id = ts_allocate_id(sizeof(php_output_globals), NULL, NULL); + output_globals_id = ts_allocate_id(sizeof(php_output_globals), (ts_allocate_ctor) php_output_init_globals, NULL); #else php_output_init_globals(OLS_C); #endif @@ -186,6 +182,18 @@ PHPAPI void php_end_ob_buffering(int send_buffer) } +PHPAPI void php_start_implicit_flush() +{ + php_end_ob_buffering(1); /* Switch out of output buffering if we're in it */ + +} + + +PHPAPI void php_end_implicit_flush() +{ +} + + /* * Output buffering - implementation */ @@ -321,6 +329,7 @@ static int php_ub_body_write_no_header(const char *str, uint str_length) free(newstr); } + return result; } @@ -347,10 +356,6 @@ static int php_ub_body_write(const char *str, uint str_length) * HEAD support */ -void set_header_request(int value) -{ - /* deprecated */ -} PHP_FUNCTION(ob_start) { @@ -378,6 +383,27 @@ PHP_FUNCTION(ob_get_contents) } +PHP_FUNCTION(ob_implicit_flush) +{ + zval **zv_flag; + int flag; + + switch(ZEND_NUM_ARGS()) { + case 0: + flag = 1; + break; + case 1: + if (zend_get_parameters_ex(1, &zv_flag)==FAILURE) { + RETURN_FALSE; + } + convert_to_long_ex(zv_flag); + flag = (*zv_flag)->value.lval; + break; + } +} + + + /* * Local variables: * tab-width: 4 diff --git a/ext/standard/php_output.h b/ext/standard/php_output.h index 63e692e2e2..17c8424429 100644 --- a/ext/standard/php_output.h +++ b/ext/standard/php_output.h @@ -27,6 +27,10 @@ PHPAPI int php_body_write(const char *str, uint str_length); PHPAPI int php_header_write(const char *str, uint str_length); PHPAPI void php_start_ob_buffering(void); PHPAPI void php_end_ob_buffering(int send_buffer); +PHPAPI int php_ob_get_buffer(pval *p); +PHPAPI void php_start_implicit_flush(); +PHPAPI void php_end_implicit_flush(); + extern zend_module_entry output_module_entry; #define phpext_output_ptr &output_module_entry |