]> granicus.if.org Git - php/commitdiff
- Added flush() support to SAPI
authorZeev Suraski <zeev@php.net>
Thu, 13 Jan 2000 17:37:25 +0000 (17:37 +0000)
committerZeev Suraski <zeev@php.net>
Thu, 13 Jan 2000 17:37:25 +0000 (17:37 +0000)
- 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)

17 files changed:
ext/session/php_session.h
ext/standard/basic_functions.c
ext/standard/head.c
ext/standard/output.c
ext/standard/php_output.h
main/SAPI.c
main/SAPI.h
main/output.c
main/php_output.h
sapi/aolserver/aolserver.c
sapi/apache/mod_php4.c
sapi/cgi/cgi_main.c
sapi/isapi/php4isapi.c
sapi/phttpd/phttpd.c
sapi/roxen/roxen.c
sapi/servlet/servlet.c
sapi/thttpd/thttpd.c

index 005b451295544db30f35ddf1744328f9e6138c72..5fa3bdd6a69f102dbbebf3537f3984127146d342 100644 (file)
@@ -152,7 +152,7 @@ typedef struct ps_serializer_struct {
 #ifdef TRANS_SID
 void session_adapt_uris(const char *, uint, char **, uint *);
 #else
-#define session_adapt_uris(a,b,c,d) do { } while(0)
+#define session_adapt_uris(a,b,c,d)
 #endif
 
 void _php_session_auto_start(void *data);
index eee7221c71c18bed6afdc1de02dc9792799dadd9..a8b1d4dc422ae7c26094981fb3c5b7b413bc1b07 100644 (file)
@@ -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();
 }
 
 
index 2fa708eda5faca0dd8c37bf49ade65e0813eb830..a6b973cec6c2fc20bfb460b4cac5f46a7d9f2473 100644 (file)
@@ -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)
index ab5ee333e74c5b9d39bfa023ce9328a534c718d1..5ba4c928312f2254d80e3784b70c45166727c7b8 100644 (file)
@@ -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
index 63e692e2e2d4361f49c957f10128c777390573e8..17c8424429730aaecbf2a2efe3ddf0b5492d305a 100644 (file)
@@ -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
index f5782321e202461e25d70fc9bf825d8a27efd347..30d0db76b109e9e9b987f308cb5cb560b14c57f0 100644 (file)
@@ -357,3 +357,15 @@ SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(char
        return SUCCESS;
 }
 
+
+SAPI_API int sapi_flush()
+{
+       if (sapi_module.flush) {
+               SLS_FETCH();
+
+               sapi_module.flush(SG(server_context));
+               return SUCCESS;
+       } else {
+               return FAILURE;
+       }
+}
index 67df3af30e90a53dd5afce010a843b62b0e2aa73..d5ebcdc62fd1655d89c6fe7c40bdf3ac05ceddf9 100644 (file)
@@ -126,6 +126,9 @@ SAPI_API int sapi_register_post_reader(sapi_post_content_type_reader *post_conte
 SAPI_API void sapi_unregister_post_reader(sapi_post_content_type_reader *post_content_type_reader);
 SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(char *content_type_dup SLS_DC));
 
+SAPI_API int sapi_flush();
+
+
 struct _sapi_module_struct {
        char *name;
 
@@ -133,6 +136,7 @@ struct _sapi_module_struct {
        int (*shutdown)(struct _sapi_module_struct *sapi_module);
 
        int (*ub_write)(const char *str, unsigned int str_length);
+       void (*flush)(void *server_context);
 
        void (*sapi_error)(int type, const char *error_msg, ...);
 
index ab5ee333e74c5b9d39bfa023ce9328a534c718d1..5ba4c928312f2254d80e3784b70c45166727c7b8 100644 (file)
@@ -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
index 63e692e2e2d4361f49c957f10128c777390573e8..17c8424429730aaecbf2a2efe3ddf0b5492d305a 100644 (file)
@@ -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
index a6e2fe96b58b90a54539ffda6b99dae781aa729d..2491c31f2d778e996b64a5fda3a3fe333c415a73 100644 (file)
@@ -297,6 +297,7 @@ static sapi_module_struct sapi_module = {
        php_module_shutdown_wrapper,                    /* shutdown */
 
        php_ns_sapi_ub_write,                                   /* unbuffered write */
+       NULL,                                                                   /* flush */
 
        php_error,                                                              /* error handler */
 
index 9b7f2a2f572e3851857fba0e72ec2f9046d0fe48..246312be3875dbf9db5f6e2da2a50de149caad55 100644 (file)
@@ -124,7 +124,7 @@ void php_save_umask(void)
 }
 
 
-static int zend_apache_ub_write(const char *str, uint str_length)
+static int sapi_apache_ub_write(const char *str, uint str_length)
 {
        int ret;
        SLS_FETCH();
@@ -143,6 +143,17 @@ static int zend_apache_ub_write(const char *str, uint str_length)
 }
 
 
+
+static void sapi_apache_flush(void *server_context)
+{
+#if MODULE_MAGIC_NUMBER > 19970110
+       rflush((request_rec *) server_context);
+#else
+       bflush((request_rec *) server_context->connection->client);
+#endif
+}
+
+
 int sapi_apache_read_post(char *buffer, uint count_bytes SLS_DC)
 {
        uint total_read_bytes=0, read_bytes;
@@ -217,7 +228,9 @@ static sapi_module_struct sapi_module = {
        php_module_startup,                             /* startup */
        php_module_shutdown_wrapper,    /* shutdown */
 
-       zend_apache_ub_write,                   /* unbuffered write */
+       sapi_apache_ub_write,                   /* unbuffered write */
+       sapi_apache_flush,                              /* flush */
+
 
        php_error,                                              /* error handler */
 
index 7e41932c08f028882f427e651467578feffe3d14..538861faabeadc989d9de30ea6f530e479ef97e0 100644 (file)
@@ -83,12 +83,18 @@ PHPAPI extern char *optarg;
 PHPAPI extern int optind;
 
 
-static int zend_cgibin_ub_write(const char *str, uint str_length)
+static int sapi_cgibin_ub_write(const char *str, uint str_length)
 {
        return fwrite(str, 1, str_length, stdout);
 }
 
 
+static void sapi_cgibin_flush(void *server_context)
+{
+       fflush(stdout);
+}
+
+
 static void sapi_cgi_send_header(sapi_header_struct *sapi_header, void *server_context)
 {
        if (sapi_header) {
@@ -126,7 +132,8 @@ static sapi_module_struct sapi_module = {
        php_module_startup,                             /* startup */
        php_module_shutdown_wrapper,    /* shutdown */
 
-       zend_cgibin_ub_write,                   /* unbuffered write */
+       sapi_cgibin_ub_write,                   /* unbuffered write */
+       sapi_cgibin_flush,                              /* flush */
 
        php_error,                                              /* error handler */
 
index 3bc02b912bcdf7cbe552ed5b29c7ee16cd590d81..f85b181d485718916ad43b8c8faae41b6d9ecbf3 100644 (file)
@@ -130,7 +130,7 @@ static zend_module_entry php_isapi_module = {
 };
 
 
-static int zend_isapi_ub_write(const char *str, uint str_length)
+static int sapi_isapi_ub_write(const char *str, uint str_length)
 {
        DWORD num_bytes = str_length;
        LPEXTENSION_CONTROL_BLOCK ecb;
@@ -296,7 +296,8 @@ static sapi_module_struct sapi_module = {
        php_isapi_startup,                              /* startup */
        php_module_shutdown_wrapper,    /* shutdown */
 
-       zend_isapi_ub_write,                    /* unbuffered write */
+       sapi_isapi_ub_write,                    /* unbuffered write */
+       NULL,                                                   /* flush */
 
        php_error,                                              /* error handler */
 
index a6697952cd7706ce235dc84ea3dc4b59fe248390..5906e16fafd9291ebcc09bfa30964198e3ea102b 100644 (file)
@@ -168,6 +168,7 @@ static sapi_module_struct sapi_module = {
     php_module_shutdown_wrapper,            /* shutdown */
  
     php_phttpd_sapi_ub_write,               /* unbuffered write */
+       NULL,                                                                   /* flush */
  
     php_error,                              /* error handler */
  
index 56d358a2d28837becb82be8d154702b60a867b4e..d9c588fa966deb22994f32d703de406d79c9c7d2 100644 (file)
@@ -519,15 +519,16 @@ static sapi_module_struct sapi_module = {
   "Roxen",
 
   php_module_startup,                                          /* startup */
-  pike_module_exit,                    /* shutdown */
+  pike_module_exit,                                                    /* shutdown */
 
   php_roxen_sapi_ub_write,                                     /* unbuffered write */
+  NULL,                                                                                /* flush */
 
   php_error,                                                           /* error handler */
 
-  php_roxen_sapi_header_handler,                               /* header handler */
+  php_roxen_sapi_header_handler,                       /* header handler */
   php_roxen_sapi_send_headers,                         /* send headers handler */
-  NULL,                                                                        /* send header handler */
+  NULL,                                                                                /* send header handler */
 
   php_roxen_sapi_read_post,                                    /* read POST data */
   php_roxen_sapi_read_cookies,                         /* read Cookies */
index 7fcce6fb3b135320dc61e9cd4d810244b0be03ed..0682dc0578878ce9918da1c1fb4041c74ca75d64 100644 (file)
@@ -122,7 +122,7 @@ void ThrowServletException (JNIEnv *jenv, char *msg) {
  * sapi callbacks
  */
 
-static int zend_servlet_ub_write(const char *str, uint str_length)
+static int sapi_servlet_ub_write(const char *str, uint str_length)
 {
        SLS_FETCH();
        if (!SG(server_context)) {
@@ -215,7 +215,8 @@ static sapi_module_struct sapi_module = {
        php_module_startup,                             /* startup */
        php_module_shutdown_wrapper,    /* shutdown */
 
-       zend_servlet_ub_write,                  /* unbuffered write */
+       sapi_servlet_ub_write,                  /* unbuffered write */
+       NULL,                                                   /* flush */
 
        php_error,                                              /* error handler */
 
index 81877c305d846444c80ecd9af972f4e862117ba3..fed6c578bd2fc7707b37bba17f387d2469203b8e 100644 (file)
@@ -108,6 +108,8 @@ static sapi_module_struct sapi_module = {
        php_module_shutdown_wrapper,
        
        sapi_thttpd_ub_write,
+       NULL,
+
        php_error,
        
        NULL,