Oracle9i Supplied PL/SQL Packages and Types Reference Release 1 (9.0.1) Part Number A89852-02 |
|
UTL_HTTP , 15 of 59
This procedure sets:
If persistent-connection support is enabled for an HTTP request, the package keeps the network connections to a Web server or the proxy server open in the package after the request is completed. A subsequent request to the same server can use the HTTP 1.1 persistent connection. With persistent connection support, subsequent HTTP requests can be completed faster because network connection latency is avoided. If the persistent-connection support is disabled for a request, the package will send the HTTP header Connection: close
automatically in the HTTP request and close the network connection when the request is completed. This setting has no effect on HTTP requests that follows HTTP 1.0 protocol, for which the network connections will always be closed after the requests are completed.
When a request is made, the package always attempts to reuse an existing persistent connection to the target Web server (or proxy server) if one is available. If none is available, a new network connection will be initiated. The persistent-connection support setting for a request affects only whether the network connection should be closed after a request completes.
Persistent-connection support is disabled for all HTTP requests in a database user session by default. The default maximum number of persistent connections saved in the current session is zero. The default setting of the persistent-connection support (enabled vs. disabled) affects only future requests and has no effect on existing requests.
After a request is created, the persistent-connection support setting can be changed by using the other set_persistent_conn_support
procedure that operates on a request.
While the use of persistent connections in UTL_HTTP
can reduce the time it takes to fetch multiple Web pages from the same server, it consumes system resources (network connections) in the database server. Excessive use of persistent connections can reduce the scalability of the database server when too many network connections are kept open in the database server. Network connections should be kept open only if they will be used immediately by subsequent requests and should be closed when they are no longer needed. You should normally disable persistent connection support in the session and enable persistent connections in individual HTTP requests, as shown in "Example: Using SET_PERSISTENT_CONN_SUPPORT".
UTL_HTTP.set_persistent_conn_support (enable IN BOOLEAN, max_conns IN PLS_INTEGER DEFAULT 0);
Table 78-17 shows the parameters for the SET_PERSISTENT_CONN_SUPPORT
procedure.
The default value of the maximum number of persistent connections in a database session is zero. To truly enable persistent connections, you must also set the maximum number of persistent connections to a positive value or no connections will be kept persistent.
DECLARE TYPE vc2_table IS TABLE OF VARCHAR2(256) INDEX BY binary_integer; paths vc2_table; PROCEDURE fetch_pages(paths IN vc2_table) AS url_prefix VARCHAR2(256) := 'http://www.my-company.com/'; req utl_http.req; resp utl_http.resp; data VARCHAR2(1024); BEGIN FOR i IN 1..paths.count LOOP req := utl_http.begin_request(url_prefix || paths(i)); -- Use persistent connection except for the last request IF (i < paths.count) THEN utl_http.set_persistent_conn_support(req, TRUE); END IF; resp := utl_http.get_response(req); BEGIN LOOP utl_http.read_text(resp, data); -- do something with the data END LOOP; EXCEPTION WHEN utl_http.end_of_body THEN NULL; END; utl_http.end_response(resp); END LOOP; END; BEGIN utl_http.set_persistent_conn_support(FALSE, 1); paths(1) := '...'; paths(2) := '...'; ... fetch_pages(paths); END;
|
Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|