You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Denis Spichkin <us...@gmail.com> on 2011/12/05 08:19:51 UTC

PIPE and mod_perl2

Hello.

Trying to write a program for mod_perl2  that gradually display its
output such as output from "ping" (output during PIPE execution).

For example
http://www.websitepulse.com/help/testreq.php?host=www.ya.ru&location=9&type=1&singletestpage=ping-test&pass=&ttref=http%3A%2F%2Fwww.websitepulse.com%2F&__=1323068838832

At the moment I was able display all output at once.  That completely
unacceptable for this type of program

        my $ping = '/bin/ping';
        my $count = '-c 10';
        open (PIPE, "$ping $count $param |");
        if (!<PIPE>) {
                $r->print("Error: can't open the pipe $!");
                return OK;
                };

        while (<PIPE>) {
            $r->write($_); # tried $r->print and $r->puts......with
the same result
            $r->write('<br />');
            };

        close (PIPE);


Please if anyone know how possible gradually display output in
mod_perl2 help me........

Re: PIPE and mod_perl2

Posted by Denis Spichkin <us...@gmail.com>.
Thank you for your replay
yes,  flush the headers is really work but only in IE (in Firefox it
doesn't work)
and its work only in cycle

        while (<PIPE>) {
            $r->rflush;
                $r->print( $_ );
           };

when i use $r->rflush only one time (before cycle ) it doesn't work.
(it set Transfer-Encoding chunked but the page is show entirely at
once)

rflush help me set follow header

Date	Mon, 05 Dec 2011 19:07:48 GMT
Server	Apache/2.2.16 (Ubuntu)
Vary	Accept-Encoding
Content-Encoding	gzip
Connection	close
Transfer-Encoding	chunked
Content-Type	text/html

but I completely don't undestand what difference between IE and
Firefox in this case.



2011/12/5 David Booth <da...@dbooth.org>:
> On Mon, 2011-12-05 at 17:39 +0400, Denis Spichkin wrote:
> [ . . . ]
>> so now I need find out how generate page with out Content-Length in mod_perl
>
> I believe you need to force Apache to flush the headers.  Otherwise it
> will try to compute and add the Content-Length header for you.  See
> http://perl.apache.org/docs/2.0/user/handlers/http.html#item_The_special_case_of__code_Content_Length__0__code_
>
>
> --
> David Booth, Ph.D.
> http://dbooth.org/
>
> Opinions expressed herein are those of the author and do not necessarily
> reflect those of his employer.
>

Re: PIPE and mod_perl2

Posted by David Booth <da...@dbooth.org>.
On Mon, 2011-12-05 at 17:39 +0400, Denis Spichkin wrote:
[ . . . ]
> so now I need find out how generate page with out Content-Length in mod_perl

I believe you need to force Apache to flush the headers.  Otherwise it
will try to compute and add the Content-Length header for you.  See
http://perl.apache.org/docs/2.0/user/handlers/http.html#item_The_special_case_of__code_Content_Length__0__code_


-- 
David Booth, Ph.D.
http://dbooth.org/

Opinions expressed herein are those of the author and do not necessarily
reflect those of his employer.


Re: PIPE and mod_perl2

Posted by Denis Spichkin <us...@gmail.com>.
Thank you for your replay

I think I have find the way of solution of my problem
the difference between situation when output is shown gradually and
when output is shown at once
is:
when: Transfer-Encoding	chunked
and unset Content-Length
the output show immediately without delay

and when:
 Transfer-Encoding: is absent
and Content-Length is set for axample Content-Length	280
 output will be show only after load all page (size 280 )

so now I need find out how generate page with out Content-Length in mod_perl


2011/12/5 Torsten Förtsch <to...@gmx.net>:
> On Monday, 05 December 2011 11:19:51 Denis Spichkin wrote:
>> Trying to write a program for mod_perl2  that gradually display its
>> output such as output from "ping" (output during PIPE execution).
>>
>> For example
>> http://www.websitepulse.com/help/testreq.php?host=www.ya.ru&location=9&type=
>> 1&singletestpage=ping-test&pass=&ttref=http%3A%2F%2Fwww.websitepulse.com%2F&
>> __=1323068838832
>>
>> At the moment I was able display all output at once.  That completely
>> unacceptable for this type of program
>>
>>         my $ping = '/bin/ping';
>>         my $count = '-c 10';
>>         open (PIPE, "$ping $count $param |");
>>         if (!<PIPE>) {
>>                 $r->print("Error: can't open the pipe $!");
>>                 return OK;
>>                 };
>>
>>         while (<PIPE>) {
>>             $r->write($_); # tried $r->print and $r->puts......with
>> the same result
>>             $r->write('<br />');
>>             };
>>
>>         close (PIPE);
>>
>>
>> Please if anyone know how possible gradually display output in
>> mod_perl2 help me........
>
> I believe your program works as expected. The rest is a browser issue. Try
> this one on the command line:
>
> perl -MIO::Socket::INET -le '
>  my $s=IO::Socket::INET->new($ARGV[0].":80");
>  $s->print("GET $ARGV[1] HTTP/1.0\r\nHost: $ARGV[0]\r\n\r\n");
>  while(<$s>) {
>    print time."\t".$_;
>  }' www.websitepulse.com
> '/help/testreq.php?host=www.ya.ru&location=9&type=1&singletestpage=ping-
> test&pass=&ttref=http%3A%2F%2Fwww.websitepulse.com%2F&__=1323068838832'
>
> Here I get the output:
>
> 1323076533      HTTP/1.1 200 OK
>
> ...
>
> 1323076533      </b></td></tr><tr bgcolor=#F5F5F5><td nowrap>64 bytes from
> www.yandex.ru (77.88.21.3): icmp_seq=0 ttl=56 time=158 ms
>
> 1323076534      </td></tr><tr bgcolor=#F5F5F5><td nowrap>64 bytes from
> www.yandex.ru (77.88.21.3): icmp_seq=1 ttl=56 time=158 ms
>
> 1323076535      </td></tr><tr bgcolor=#F5F5F5><td nowrap>64 bytes from
> www.yandex.ru (77.88.21.3): icmp_seq=2 ttl=56 time=158 ms
>
> 1323076536      </td></tr><tr bgcolor=#F5F5F5><td nowrap>64 bytes from
> www.yandex.ru (77.88.21.3): icmp_seq=3 ttl=56 time=158 ms
>
> 1323076537      </td></tr><tr bgcolor=#F5F5F5><td nowrap>64 bytes from
> www.yandex.ru (77.88.21.3): icmp_seq=4 ttl=56 time=158 ms
>
> 1323076537      </td></tr><tr bgcolor=#F5F5F5><td nowrap>
>
> You see the first few lines come in at the same time. Then between each of the
> ping output lines is an interval of 1 sec.
>
> The reason why you don't see it immediately in the browser window is the
> browser rendering.
>
> Have a look also at:
>
> http://foertsch.name/ModPerl-Tricks/ServerPush.shtml
> http://foertsch.name/ModPerl-Tricks/req-hand-over.shtml
>
> Torsten Förtsch
>
> --
> Need professional modperl support? Hire me! (http://foertsch.name)
>
> Like fantasy? http://kabatinte.net
>

Re: PIPE and mod_perl2

Posted by Torsten Förtsch <to...@gmx.net>.
On Monday, 05 December 2011 11:19:51 Denis Spichkin wrote:
> Trying to write a program for mod_perl2  that gradually display its
> output such as output from "ping" (output during PIPE execution).
> 
> For example
> http://www.websitepulse.com/help/testreq.php?host=www.ya.ru&location=9&type=
> 1&singletestpage=ping-test&pass=&ttref=http%3A%2F%2Fwww.websitepulse.com%2F&
> __=1323068838832
> 
> At the moment I was able display all output at once.  That completely
> unacceptable for this type of program
> 
>         my $ping = '/bin/ping';
>         my $count = '-c 10';
>         open (PIPE, "$ping $count $param |");
>         if (!<PIPE>) {
>                 $r->print("Error: can't open the pipe $!");
>                 return OK;
>                 };
> 
>         while (<PIPE>) {
>             $r->write($_); # tried $r->print and $r->puts......with
> the same result
>             $r->write('<br />');
>             };
> 
>         close (PIPE);
> 
> 
> Please if anyone know how possible gradually display output in
> mod_perl2 help me........

I believe your program works as expected. The rest is a browser issue. Try 
this one on the command line:

perl -MIO::Socket::INET -le '
  my $s=IO::Socket::INET->new($ARGV[0].":80");
  $s->print("GET $ARGV[1] HTTP/1.0\r\nHost: $ARGV[0]\r\n\r\n");
  while(<$s>) {
    print time."\t".$_;
  }' www.websitepulse.com 
'/help/testreq.php?host=www.ya.ru&location=9&type=1&singletestpage=ping-
test&pass=&ttref=http%3A%2F%2Fwww.websitepulse.com%2F&__=1323068838832'

Here I get the output:

1323076533      HTTP/1.1 200 OK

...

1323076533      </b></td></tr><tr bgcolor=#F5F5F5><td nowrap>64 bytes from 
www.yandex.ru (77.88.21.3): icmp_seq=0 ttl=56 time=158 ms

1323076534      </td></tr><tr bgcolor=#F5F5F5><td nowrap>64 bytes from 
www.yandex.ru (77.88.21.3): icmp_seq=1 ttl=56 time=158 ms

1323076535      </td></tr><tr bgcolor=#F5F5F5><td nowrap>64 bytes from 
www.yandex.ru (77.88.21.3): icmp_seq=2 ttl=56 time=158 ms

1323076536      </td></tr><tr bgcolor=#F5F5F5><td nowrap>64 bytes from 
www.yandex.ru (77.88.21.3): icmp_seq=3 ttl=56 time=158 ms

1323076537      </td></tr><tr bgcolor=#F5F5F5><td nowrap>64 bytes from 
www.yandex.ru (77.88.21.3): icmp_seq=4 ttl=56 time=158 ms

1323076537      </td></tr><tr bgcolor=#F5F5F5><td nowrap>

You see the first few lines come in at the same time. Then between each of the 
ping output lines is an interval of 1 sec.

The reason why you don't see it immediately in the browser window is the 
browser rendering.

Have a look also at:

http://foertsch.name/ModPerl-Tricks/ServerPush.shtml
http://foertsch.name/ModPerl-Tricks/req-hand-over.shtml

Torsten Förtsch

-- 
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net