# 22. Virtuoso Functions Guide - http_flush

Chapter Contents | Prev | Next
Keyword Search:
www.openlinksw.com
docs.openlinksw.com
Book Home
Contents
Preface
Virtuoso Functions Guide
Administration
Aggregate Functions
Array Manipulation
BPEL APIs
Backup
Compression
Cursor
Date & Time Manipulation
Debug
Dictionary Manipulation
Encoding & Decoding
File Manipulation
Free Text
Hashing / Cryptographic
LDAP
Locale
Mail
Miscellaneous
Number
Remote SQL Data Source
Replication
SOAP
SQL
String
Transaction
Type Mapping
UDDI
User Defined Types & The CLR
Virtuoso Java PL API
Virtuoso Server Extension Interface (VSEI)
Web Server & Internet
dav add & update fun...
dav manipulation fun...
dav search functions
dav_exp
lfs_exp
serv_queue_top
vhost_define
vhost_remove
webdav users & group...
client_attr
connection_get
connection_id
connection_is_dirty
connection_set
connection_vars
connection_vars_set
dbname
ftp_get
ftp_ls
ftp_put
get_certificate_info
get_keyword
get_keyword_ucase
http
http_acl_get
http_body_read
http_client
http_client_ip
http_debug_log
http_enable_gz
http_file
http_flush
http_get
http_header
http_header_get
http_kill
http_listen_host
http_map_get
http_map_table
http_param
http_path
http_pending_req
http_physical_path
http_proxy
http_request_get
http_request_header
http_request_status
http_rewrite
http_root
http_url
http_value
http_xslt
ses_connect
ses_disconnect
ses_read_line
ses_write
tcpip_gethostbyaddr
tcpip_gethostbyname
vsp_calculate_digest
wsdl_import_udt
XML
XPATH & XQUERY
Functions Index

## http_flush

Flush internal HTTP stream and disconnect client; Flush HTTP stream and try sending data in chunked mode.
http_flush ([in try_what integer]);
Description

This flushes the internal buffer where output of a VSP page is stored pending the execution of the page's code. This sends the content of the page output buffer along with headers and disconnects the client. The status is 200 OK by default, unless overridden by http_status. The purpose of this function is to allow a page to send output before terminating , thus the page can continue processing for an indefinite time without requiring the client to wait. This is useful for starting long running background tasks from HTTP clients.

VSP pages that use this function must be sure to supply appropriate content (or response headers) if needed before calling this function.

Virtuoso supports HTTP 1.1 Chunking Encoding which allows Virtuoso to send the user agent chunks of output as the page is still processing. Chunking is enabled by calling http_flush(1) within the VSP page. By default chunks are sent for every 4k worth of output generated, but in some cases the output needs to consist of smaller chunks, for example when run-time status needs to be shown in a status page. So to achieve this the http_flush (try_what=1) could be invoked in places where chunk must be flushed to the User agent.

Chunked mode requires the following conditions:

- no "Content-Length" header sent to the client using http_header()
- no "Content-Encoding" header sent to the client using http_header()
- use http_xslt() is not permitted
- The client supports HTTP 1.1

Failing these conditions, http_flush(1) will be a No-Operation.

If the function has actually switched to chunked mode it will return a non-zero integer. Otherwise and integer 0 will be returned.

Chunked mode is not supported for static content.

Parameters
try_what – This optional parameter can be supplied the value one (1) to instruct Virtuoso to try sending the output of the VSP page in chunked mode.
Examples
Using http_flush()

      <?vsp
        http ('<p>Hit <a href="status.vsp">there</a> to go on status page</p>');
        http_flush ();
        long_task_procedure ();
      ?>

Using http_flush() small chunks

The following example will render in browser at every loop iteration 'state=N'; so this will be visible at 'run-time' not when loop finished which may take a long.

    <?vsp
      ....
      http_flush (1);

      while (i<1000)
        {
          process_some_item (); -- some procedure that takes a long time usually
          http ('state='||cast (i as varchar)||'<br>');
          http_flush (1);
          i := i + 1;
        }
    ?>

See Also

http, http_value, http_url, string_output, http_rewrite.