1CGI::Push(3)          User Contributed Perl Documentation         CGI::Push(3)
2
3
4

NAME

6       CGI::Push - Simple Interface to Server Push
7

SYNOPSIS

9           use strict;
10           use warnings;
11
12           use CGI::Push qw(:standard);
13
14           do_push(
15               -next_page => \&next_page,
16               -last_page => \&last_page,
17               -delay     => 0.5
18           );
19
20           sub next_page {
21               my($q,$counter) = @_;
22               return undef if $counter >= 10;
23               ....
24           }
25
26           sub last_page {
27               my($q,$counter) = @_;
28               return ...
29           }
30

DESCRIPTION

32       CGI::Push is a subclass of the CGI object created by CGI.pm.  It is
33       specialized for server push operations, which allow you to create
34       animated pages whose content changes at regular intervals.
35
36       You provide CGI::Push with a pointer to a subroutine that will draw one
37       page.  Every time your subroutine is called, it generates a new page.
38       The contents of the page will be transmitted to the browser in such a
39       way that it will replace what was there beforehand.  The technique will
40       work with HTML pages as well as with graphics files, allowing you to
41       create animated GIFs.
42
43       Only Netscape Navigator supports server push.  Internet Explorer
44       browsers do not.
45

USING CGI::Push

47       CGI::Push adds one new method to the standard CGI suite, do_push().
48       When you call this method, you pass it a reference to a subroutine that
49       is responsible for drawing each new page, an interval delay, and an
50       optional subroutine for drawing the last page.  Other optional
51       parameters include most of those recognized by the CGI header() method.
52
53       You may call do_push() in the object oriented manner or not, as you
54       prefer:
55
56           use CGI::Push;
57           $q = CGI::Push->new;
58           $q->do_push(-next_page=>\&draw_a_page);
59
60               -or-
61
62           use CGI::Push qw(:standard);
63           do_push(-next_page=>\&draw_a_page);
64
65       Parameters are as follows:
66
67       -next_page
68               do_push(-next_page=>\&my_draw_routine);
69
70           This required parameter points to a reference to a subroutine
71           responsible for drawing each new page.  The subroutine should
72           expect two parameters consisting of the CGI object and a counter
73           indicating the number of times the subroutine has been called.  It
74           should return the contents of the page as an array of one or more
75           items to print.  It can return a false value (or an empty array) in
76           order to abort the redrawing loop and print out the final page (if
77           any)
78
79               sub my_draw_routine {
80                   my($q,$counter) = @_;
81                   return undef if $counter > 100;
82                   ...
83               }
84
85           You are of course free to refer to create and use global variables
86           within your draw routine in order to achieve special effects.
87
88       -last_page
89           This optional parameter points to a reference to the subroutine
90           responsible for drawing the last page of the series.  It is called
91           after the -next_page routine returns a false value.  The subroutine
92           itself should have exactly the same calling conventions as the
93           -next_page routine.
94
95       -type
96           This optional parameter indicates the content type of each page.
97           It defaults to "text/html".  Normally the module assumes that each
98           page is of a homogeneous MIME type.  However if you provide either
99           of the magic values "heterogeneous" or "dynamic" (the latter
100           provided for the convenience of those who hate long parameter
101           names), you can specify the MIME type -- and other header fields --
102           on a per-page basis.  See "heterogeneous pages" for more details.
103
104       -delay
105           This indicates the delay, in seconds, between frames.  Smaller
106           delays refresh the page faster.  Fractional values are allowed.
107
108           If not specified, -delay will default to 1 second
109
110       -cookie, -target, -expires, -nph
111           These have the same meaning as the like-named parameters in
112           CGI::header().
113
114           If not specified, -nph will default to 1 (as needed for many
115           servers, see below).
116
117   Heterogeneous Pages
118       Ordinarily all pages displayed by CGI::Push share a common MIME type.
119       However by providing a value of "heterogeneous" or "dynamic" in the
120       do_push() -type parameter, you can specify the MIME type of each page
121       on a case-by-case basis.
122
123       If you use this option, you will be responsible for producing the HTTP
124       header for each page.  Simply modify your draw routine to look like
125       this:
126
127           sub my_draw_routine {
128               my($q,$counter) = @_;
129               return header('text/html'),   # note we're producing the header here
130               ....
131           }
132
133       You can add any header fields that you like, but some (cookies and
134       status fields included) may not be interpreted by the browser.  One
135       interesting effect is to display a series of pages, then, after the
136       last page, to redirect the browser to a new URL.  Because redirect()
137       does b<not> work, the easiest way is with a -refresh header field, as
138       shown below:
139
140           sub my_draw_routine {
141               my($q,$counter) = @_;
142               return undef if $counter > 10;
143               return header('text/html'),   # note we're producing the header here
144               ...
145           }
146
147           sub my_last_page {
148               return header(-refresh=>'5; URL=http://somewhere.else/finished.html',
149                             -type=>'text/html'),
150               ...
151           }
152
153   Changing the Page Delay on the Fly
154       If you would like to control the delay between pages on a page-by-page
155       basis, call push_delay() from within your draw routine.  push_delay()
156       takes a single numeric argument representing the number of seconds you
157       wish to delay after the current page is displayed and before displaying
158       the next one.  The delay may be fractional.  Without parameters,
159       push_delay() just returns the current delay.
160

INSTALLING CGI::Push SCRIPTS

162       Server push scripts must be installed as no-parsed-header (NPH) scripts
163       in order to work correctly on many servers.  On Unix systems, this is
164       most often accomplished by prefixing the script's name with "nph-".
165       Recognition of NPH scripts happens automatically with WebSTAR and
166       Microsoft IIS.  Users of other servers should see their documentation
167       for help.
168
169       Apache web server from version 1.3b2 on does not need server push
170       scripts installed as NPH scripts: the -nph parameter to do_push() may
171       be set to a false value to disable the extra headers needed by an NPH
172       script.
173

AUTHOR INFORMATION

175       The CGI.pm distribution is copyright 1995-2007, Lincoln D. Stein. It is
176       distributed under the Artistic License 2.0. It is currently maintained
177       by Lee Johnson with help from many contributors.
178
179       Address bug reports and comments to:
180       https://github.com/leejo/CGI.pm/issues
181
182       The original bug tracker can be found at:
183       https://rt.cpan.org/Public/Dist/Display.html?Queue=CGI.pm
184
185       When sending bug reports, please provide the version of CGI.pm, the
186       version of Perl, the name and version of your Web server, and the name
187       and version of the operating system you are using.  If the problem is
188       even remotely browser dependent, please provide information about the
189       affected browsers as well.  Copyright 1995-1998, Lincoln D. Stein.  All
190       rights reserved.
191

BUGS

193       This section intentionally left blank.
194

SEE ALSO

196       CGI::Carp, CGI
197
198
199
200perl v5.36.1                      2023-05-04                      CGI::Push(3)
Impressum