Loading ...
Sorry, an error occurred while loading the content.

$| doesn't work with mod_perl

Expand Messages
  • pradeep kumar
    Hi, I have a perl script which uses $| to set autoflush on. Basically, it flushes after every print. This script is working fine from the command line when run
    Message 1 of 12 , Sep 1 5:52 AM
    • 0 Attachment
      Hi,

       I have a perl script which uses $| to set autoflush on. Basically, it flushes after every print. This script is working fine from the command line when run using standalone perl interpreter. But when the same script is accessed via mod_perl/apache setup, mod_perl is not flushing after every print, instead buffering and printing all output at one shot.
      Any idea why $| is not working with mod_perl.

      Here is my sample script:

      #!/usr/bin/perl -w

      use CGI qw/:standard/;
      use strict;
      select(STDOUT);
      $| = 1;
      print STDOUT "Content-type: text/html\n\n"; print STDOUT <<END; <html> <head> </head> <body> END print STDOUT 'hello'; print STDOUT '<br>'; sleep(2); print STDOUT 'World'; print STDOUT '<br>'; sleep(2); print STDOUT 'Testing'; print STDOUT "</body></html>";


      Thanks in advance,
      Pradeep
    • Alexander Charbonnet
      Do you have mod_deflate active in your output chain? mod_deflate slurps up all its input and only prints when its buffer gets full.
      Message 2 of 12 , Sep 1 5:56 AM
      • 0 Attachment
        Do you have mod_deflate active in your output chain? mod_deflate slurps up
        all its input and only prints when its buffer gets full.

        On Thursday 01 September 2005 07:52 am, pradeep kumar wrote:
        > Hi,
        >
        > I have a perl script which uses $| to set autoflush on. Basically, it
        > flushes after every print. This script is working fine from the command
        > line when run using standalone perl interpreter. But when the same script
        > is accessed via mod_perl/apache setup, mod_perl is not flushing after every
        > print, instead buffering and printing all output at one shot.
        > Any idea why $| is not working with mod_perl.
        >
        > Here is my sample script:
        >
        > #!/usr/bin/perl -w
        >
        > use CGI qw/:standard/;
        > use strict;
        > select(STDOUT);
        > $| = 1;
        > print STDOUT "Content-type: text/html\n\n"; print STDOUT <<END; <html>
        > <head> </head> <body> END print STDOUT 'hello'; print STDOUT '<br>';
        > sleep(2); print STDOUT 'World'; print STDOUT '<br>'; sleep(2); print STDOUT
        > 'Testing'; print STDOUT "</body></html>";
        >
        >
        > Thanks in advance,
        > Pradeep
      • Alexander Charbonnet
        Also, as long as you re using CGI.pm, you should use it to generate your HTML output. Your script should probably look like this: #!/usr/bin/perl -w use
        Message 3 of 12 , Sep 1 6:01 AM
        • 0 Attachment
          Also, as long as you're using CGI.pm, you should use it to generate your HTML
          output. Your script should probably look like this:

          #!/usr/bin/perl -w

          use strict;
          use CGI qw/:standard/;

          print
          header(),
          p('hello world'),
          ;
          sleep 2;
          print
          p('testing'),
          end_html(),
          ;

          That'll generate XHTML Transitional compliant code, without having keep up
          with it yourself (too much).


          On Thursday 01 September 2005 07:56 am, Alexander Charbonnet wrote:
          > Do you have mod_deflate active in your output chain? mod_deflate slurps up
          > all its input and only prints when its buffer gets full.
          >
          > On Thursday 01 September 2005 07:52 am, pradeep kumar wrote:
          > > Hi,
          > >
          > > I have a perl script which uses $| to set autoflush on. Basically, it
          > > flushes after every print. This script is working fine from the command
          > > line when run using standalone perl interpreter. But when the same script
          > > is accessed via mod_perl/apache setup, mod_perl is not flushing after
          > > every print, instead buffering and printing all output at one shot.
          > > Any idea why $| is not working with mod_perl.
          > >
          > > Here is my sample script:
          > >
          > > #!/usr/bin/perl -w
          > >
          > > use CGI qw/:standard/;
          > > use strict;
          > > select(STDOUT);
          > > $| = 1;
          > > print STDOUT "Content-type: text/html\n\n"; print STDOUT <<END; <html>
          > > <head> </head> <body> END print STDOUT 'hello'; print STDOUT '<br>';
          > > sleep(2); print STDOUT 'World'; print STDOUT '<br>'; sleep(2); print
          > > STDOUT 'Testing'; print STDOUT "</body></html>";
          > >
          > >
          > > Thanks in advance,
          > > Pradeep
        • Tom Schindl
          ... Hash: SHA1 What version of mp are you using if you are running mp2 i think the apache-filter-system is the problem. Tom ... Version: GnuPG v1.4.0
          Message 4 of 12 , Sep 12 1:31 AM
          • 0 Attachment
            -----BEGIN PGP SIGNED MESSAGE-----
            Hash: SHA1

            What version of mp are you using if you are running mp2 i think the
            apache-filter-system is the problem.

            Tom

            pradeep kumar wrote:
            > Hi,
            >
            > I have a perl script which uses $| to set autoflush on. Basically, it
            > flushes after every print. This script is working fine from the command
            > line when run using standalone perl interpreter. But when the same
            > script is accessed via mod_perl/apache setup, mod_perl is not flushing
            > after every print, instead buffering and printing all output at one shot.
            > Any idea why $| is not working with mod_perl.
            >
            > Here is my sample script:
            >
            > #!/usr/bin/perl -w
            >
            > use CGI qw/:standard/;
            > use strict;
            > select(STDOUT);
            > $| = 1;
            > print STDOUT "Content-type: text/html\n\n"; print STDOUT <<END; <html>
            > <head> </head> <body> END print STDOUT 'hello'; print STDOUT '<br>';
            > sleep(2); print STDOUT 'World'; print STDOUT '<br>'; sleep(2); print
            > STDOUT 'Testing'; print STDOUT "</body></html>";
            >
            >
            > Thanks in advance,
            > Pradeep

            -----BEGIN PGP SIGNATURE-----
            Version: GnuPG v1.4.0 (GNU/Linux)
            Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

            iD8DBQFDJTzSkVPeOFLgZFIRApj0AKCMTBdxV+2QHD3A09oXuZH86Qv1/wCgoSuu
            8w1b1u2xYzy6lZF9XJA3GD8=
            =VjYy
            -----END PGP SIGNATURE-----
          • pradeep kumar
            Hi Tom, I am using mp2. Thanks and Regards, Pradeep
            Message 5 of 12 , Sep 12 1:37 AM
            • 0 Attachment
              Hi Tom,
               
              I am using mp2.
               
              Thanks and Regards,
              Pradeep

               
              On 9/12/05, Tom Schindl <tomAtLinux@...> wrote:
              -----BEGIN PGP SIGNED MESSAGE-----
              Hash: SHA1

              What version of mp are you using if you are running mp2 i think the
              apache-filter-system is the problem.

              Tom

              pradeep kumar wrote:
              > Hi,
              >
              >  I have a perl script which uses $| to set autoflush on. Basically, it
              > flushes after every print. This script is working fine from the command
              > line when run using standalone perl interpreter. But when the same
              > script is accessed via mod_perl/apache setup, mod_perl is not flushing
              > after every print, instead buffering and printing all output at one shot.
              > Any idea why $| is not working with mod_perl.
              >
              > Here is my sample script:
              >
              > #!/usr/bin/perl -w
              >
              > use CGI qw/:standard/;
              > use strict;
              > select(STDOUT);
              > $| = 1;
              > print STDOUT "Content-type: text/html\n\n"; print STDOUT <<END; <html>
              > <head> </head> <body> END print STDOUT 'hello'; print STDOUT '<br>';
              > sleep(2); print STDOUT 'World'; print STDOUT '<br>'; sleep(2); print
              > STDOUT 'Testing'; print STDOUT "</body></html>";
              >
              >
              > Thanks in advance,
              > Pradeep

              -----BEGIN PGP SIGNATURE-----
              Version: GnuPG v1.4.0 (GNU/Linux)
              Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

              iD8DBQFDJTzSkVPeOFLgZFIRApj0AKCMTBdxV+2QHD3A09oXuZH86Qv1/wCgoSuu
              8w1b1u2xYzy6lZF9XJA3GD8=
              =VjYy
              -----END PGP SIGNATURE-----

            • pradeep kumar
              Can you please elaborate on why apache filters can be an issue with the autoflush problem that I noticed ? Also, I noticed that the autoflush work properly
              Message 6 of 12 , Sep 16 3:36 AM
              • 0 Attachment
                Can you please elaborate on why apache filters can be an issue with the autoflush problem that I noticed ?

                Also, I noticed that the autoflush work properly when I flush it to a regular file. Its only when I choose STDOUT that the flushing gets delayed. Is there some buffering that happens with STDOUT alone ? I am confused if this is a modperl problem or an Apache problem.

                On 9/12/05, pradeep kumar <pradeep.smani@... > wrote:
                Hi Tom,
                 
                I am using mp2.
                 
                Thanks and Regards,
                Pradeep

                 
                On 9/12/05, Tom Schindl <tomAtLinux@...> wrote:
                -----BEGIN PGP SIGNED MESSAGE-----
                Hash: SHA1

                What version of mp are you using if you are running mp2 i think the
                apache-filter-system is the problem.

                Tom

                pradeep kumar wrote:
                > Hi,
                >
                >  I have a perl script which uses $| to set autoflush on. Basically, it
                > flushes after every print. This script is working fine from the command
                > line when run using standalone perl interpreter. But when the same
                > script is accessed via mod_perl/apache setup, mod_perl is not flushing
                > after every print, instead buffering and printing all output at one shot.
                > Any idea why $| is not working with mod_perl.
                >
                > Here is my sample script:
                >
                > #!/usr/bin/perl -w
                >
                > use CGI qw/:standard/;
                > use strict;
                > select(STDOUT);
                > $| = 1;
                > print STDOUT "Content-type: text/html\n\n"; print STDOUT <<END; <html>
                > <head> </head> <body> END print STDOUT 'hello'; print STDOUT '<br>';
                > sleep(2); print STDOUT 'World'; print STDOUT '<br>'; sleep(2); print
                > STDOUT 'Testing'; print STDOUT "</body></html>";
                >
                >
                > Thanks in advance,
                > Pradeep

                -----BEGIN PGP SIGNATURE-----
                Version: GnuPG v1.4.0 (GNU/Linux)
                Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

                iD8DBQFDJTzSkVPeOFLgZFIRApj0AKCMTBdxV+2QHD3A09oXuZH86Qv1/wCgoSuu
                8w1b1u2xYzy6lZF9XJA3GD8=
                =VjYy
                -----END PGP SIGNATURE-----


              • Tom Schindl
                ... Hash: SHA1 ... Well I guess that I read it a while ago but I m not sure of. As far as I understand the Apache2-Filter-System because a bucket is only sent
                Message 7 of 12 , Sep 19 10:24 PM
                • 0 Attachment
                  -----BEGIN PGP SIGNED MESSAGE-----
                  Hash: SHA1

                  pradeep kumar wrote:
                  > Can you please elaborate on why apache filters can be an issue with the
                  > autoflush problem that I noticed ?
                  >
                  > Also, I noticed that the autoflush work properly when I flush it to a
                  > regular file. Its only when I choose STDOUT that the flushing gets
                  > delayed. Is there some buffering that happens with STDOUT alone ? I am
                  > confused if this is a modperl problem or an Apache problem.
                  >

                  Well I guess that I read it a while ago but I'm not sure of. As far as I
                  understand the Apache2-Filter-System because a bucket is only sent to
                  the filter system after the BUFFER is full. But I really have no idea
                  what happens behind the scences after the print-call.

                  Maybe Stas, Geoff or someone else can look at this and tell you more.

                  Tom
                  -----BEGIN PGP SIGNATURE-----
                  Version: GnuPG v1.4.0 (GNU/Linux)
                  Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

                  iD8DBQFDL5z2kVPeOFLgZFIRAn2iAJ4up4gQt5kptn558HyuHPVyoA72zACgmxKE
                  R6W7w6o5azBVbiidKGuxVVM=
                  =NbtZ
                  -----END PGP SIGNATURE-----
                • Alexander Charbonnet
                  Are you sure mod_deflate isn t one of your active Apache filters? mod_deflate will not output until its buffer is full, $| notwithstanding. I tore my hair
                  Message 8 of 12 , Sep 19 10:38 PM
                  • 0 Attachment
                    Are you sure mod_deflate isn't one of your active Apache filters? mod_deflate
                    will not output until its buffer is full, $| notwithstanding. I tore my hair
                    out trying to work around it, and ended up writing my own compression filter.
                    But if you don't need compression, try disabling mod_deflate.

                    -Alex


                    On Friday 16 September 2005 05:36 am, pradeep kumar wrote:
                    > Can you please elaborate on why apache filters can be an issue with the
                    > autoflush problem that I noticed ?
                    >
                    > Also, I noticed that the autoflush work properly when I flush it to a
                    > regular file. Its only when I choose STDOUT that the flushing gets delayed.
                    > Is there some buffering that happens with STDOUT alone ? I am confused if
                    > this is a modperl problem or an Apache problem.
                    >
                    > On 9/12/05, pradeep kumar <pradeep.smani@...> wrote:
                    > > Hi Tom,
                    > > I am using mp2.
                    > > Thanks and Regards,
                    > > Pradeep
                    > >
                    > > On 9/12/05, Tom Schindl <tomAtLinux@...> wrote:
                    > > > -----BEGIN PGP SIGNED MESSAGE-----
                    > > > Hash: SHA1
                    > > >
                    > > > What version of mp are you using if you are running mp2 i think the
                    > > > apache-filter-system is the problem.
                    > > >
                    > > > Tom
                    > > >
                    > > > pradeep kumar wrote:
                    > > > > Hi,
                    > > > >
                    > > > > I have a perl script which uses $| to set autoflush on. Basically, it
                    > > > > flushes after every print. This script is working fine from the
                    > > >
                    > > > command
                    > > >
                    > > > > line when run using standalone perl interpreter. But when the same
                    > > > > script is accessed via mod_perl/apache setup, mod_perl is not
                    > > > > flushing after every print, instead buffering and printing all output
                    > > > > at one
                    > > >
                    > > > shot.
                    > > >
                    > > > > Any idea why $| is not working with mod_perl.
                    > > > >
                    > > > > Here is my sample script:
                    > > > >
                    > > > > #!/usr/bin/perl -w
                    > > > >
                    > > > > use CGI qw/:standard/;
                    > > > > use strict;
                    > > > > select(STDOUT);
                    > > > > $| = 1;
                    > > > > print STDOUT "Content-type: text/html\n\n"; print STDOUT <<END;
                    > > > > <html> <head> </head> <body> END print STDOUT 'hello'; print STDOUT
                    > > > > '<br>'; sleep(2); print STDOUT 'World'; print STDOUT '<br>';
                    > > > > sleep(2); print STDOUT 'Testing'; print STDOUT "</body></html>";
                    > > > >
                    > > > >
                    > > > > Thanks in advance,
                    > > > > Pradeep
                    > > >
                    > > > -----BEGIN PGP SIGNATURE-----
                    > > > Version: GnuPG v1.4.0 (GNU/Linux)
                    > > > Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org
                    > > >
                    > > > iD8DBQFDJTzSkVPeOFLgZFIRApj0AKCMTBdxV+2QHD3A09oXuZH86Qv1/wCgoSuu
                    > > > 8w1b1u2xYzy6lZF9XJA3GD8=
                    > > > =VjYy
                    > > > -----END PGP SIGNATURE-----
                  • Philip M. Gollucci
                    ... You might try Apache2::DebugFilter to look at the bucket contents. Its pretty well documented. Its in my CPAN dir, previously by Stas. -- END ... What
                    Message 9 of 12 , Sep 20 11:33 AM
                    • 0 Attachment
                      Alexander Charbonnet wrote:
                      > Are you sure mod_deflate isn't one of your active Apache filters? mod_deflate
                      > will not output until its buffer is full, $| notwithstanding. I tore my hair
                      > out trying to work around it, and ended up writing my own compression filter.
                      > But if you don't need compression, try disabling mod_deflate.
                      You might try Apache2::DebugFilter to look at the bucket contents. Its pretty well documented.


                      Its in my CPAN dir, previously by Stas.


                      --
                      END
                      ------------------------------------------------------------
                      What doesn't kill us can only make us stronger.
                      Nothing is impossible.

                      Philip M. Gollucci (pgollucci@...) 301.254.5198
                      Consultant / http://p6m7g8.net/Resume/
                      Senior Developer / Liquidity Services, Inc.
                      http://www.liquidityservicesinc.com
                      http://www.liquidation.com
                      http://www.uksurplus.com
                      http://www.govliquidation.com
                      http://www.gowholesale.com
                    • Tom Schindl
                      ... Hash: SHA1 Does $r- rflush(); help? Although it should do the same then seting $| to undef. Tom ... Version: GnuPG v1.4.0 (GNU/Linux) Comment: Using GnuPG
                      Message 10 of 12 , Sep 23 12:54 AM
                      • 0 Attachment
                        -----BEGIN PGP SIGNED MESSAGE-----
                        Hash: SHA1

                        Does $r->rflush(); help? Although it should do the same then seting $|
                        to undef.

                        Tom

                        Tom Schindl wrote:
                        > pradeep kumar wrote:
                        >
                        >>>Can you please elaborate on why apache filters can be an issue with the
                        >>>autoflush problem that I noticed ?
                        >>>
                        >>>Also, I noticed that the autoflush work properly when I flush it to a
                        >>>regular file. Its only when I choose STDOUT that the flushing gets
                        >>>delayed. Is there some buffering that happens with STDOUT alone ? I am
                        >>>confused if this is a modperl problem or an Apache problem.
                        >>>
                        >
                        >
                        > Well I guess that I read it a while ago but I'm not sure of. As far as I
                        > understand the Apache2-Filter-System because a bucket is only sent to
                        > the filter system after the BUFFER is full. But I really have no idea
                        > what happens behind the scences after the print-call.
                        >
                        > Maybe Stas, Geoff or someone else can look at this and tell you more.
                        >
                        > Tom
                        -----BEGIN PGP SIGNATURE-----
                        Version: GnuPG v1.4.0 (GNU/Linux)
                        Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

                        iD8DBQFDM7TOkVPeOFLgZFIRAmewAJ9gR/jcCR0YitKzNTOzen6QQph25QCfYkBA
                        6m1LigFv/t2L7512tyICVpw=
                        =QcQk
                        -----END PGP SIGNATURE-----
                      • pradeep kumar
                        mod_deflate is not loaded on my system and I can still see this problem. I instrumented some portion of the code to understand the flow and I have some
                        Message 11 of 12 , Sep 26 6:21 AM
                        • 0 Attachment
                          mod_deflate is not loaded on my system and I can still see this problem.

                          I instrumented some portion of the code to understand the flow and I have some questions. The modperl_filter.c has a function modperl_wbucket_flush(). Now the add_flush_bucket variable that is passed to this function is not set even when $| is enabled. If I manually set it, the autoflush happens as expected. I wanted to know when this variable is set and why setting it manually seems to solve the problem.

                          Thanks in advance for any help on this.


                          On 9/23/05, Tom Schindl <tomAtLinux@...> wrote:
                          -----BEGIN PGP SIGNED MESSAGE-----
                          Hash: SHA1

                          Does $r->rflush(); help? Although it should do the same then seting $|
                          to undef.

                          Tom

                          Tom Schindl wrote:
                          > pradeep kumar wrote:
                          >
                          >>>Can you please elaborate on why apache filters can be an issue with the
                          >>>autoflush problem that I noticed ?
                          >>>
                          >>>Also, I noticed that the autoflush work properly when I flush it to a
                          >>>regular file. Its only when I choose STDOUT that the flushing gets
                          >>>delayed. Is there some buffering that happens with STDOUT alone ? I am
                          >>>confused if this is a modperl problem or an Apache problem.
                          >>>
                          >
                          >
                          > Well I guess that I read it a while ago but I'm not sure of. As far as I
                          > understand the Apache2-Filter-System because a bucket is only sent to
                          > the filter system after the BUFFER is full. But I really have no idea
                          > what happens behind the scences after the print-call.
                          >
                          > Maybe Stas, Geoff or someone else can look at this and tell you more.
                          >
                          > Tom
                          -----BEGIN PGP SIGNATURE-----
                          Version: GnuPG v1.4.0 (GNU/Linux)
                          Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

                          iD8DBQFDM7TOkVPeOFLgZFIRAmewAJ9gR/jcCR0YitKzNTOzen6QQph25QCfYkBA
                          6m1LigFv/t2L7512tyICVpw=
                          =QcQk
                          -----END PGP SIGNATURE-----

                        • Tom Schindl
                          ... Hash: SHA1 Hi pradeep, is $r- flush(); working, or not? Tom ... Version: GnuPG v1.4.0 (GNU/Linux) Comment: Using GnuPG with Mandriva -
                          Message 12 of 12 , Oct 4, 2005
                          • 0 Attachment
                            -----BEGIN PGP SIGNED MESSAGE-----
                            Hash: SHA1

                            Hi pradeep,

                            is $r->flush(); working, or not?

                            Tom

                            pradeep kumar wrote:
                            > mod_deflate is not loaded on my system and I can still see this problem.
                            >
                            > I instrumented some portion of the code to understand the flow and I
                            > have some questions. The modperl_filter.c has a function
                            > modperl_wbucket_flush(). Now the add_flush_bucket variable that is
                            > passed to this function is not set even when $| is enabled. If I
                            > manually set it, the autoflush happens as expected. I wanted to know
                            > when this variable is set and why setting it manually seems to solve the
                            > problem.
                            >
                            > Thanks in advance for any help on this.
                            >
                            >
                            > On 9/23/05, *Tom Schindl* <tomAtLinux@... <mailto:tomAtLinux@...>>
                            > wrote:
                            >
                            > Does $r->rflush(); help? Although it should do the same then seting $|
                            > to undef.
                            >
                            > Tom
                            >
                            > Tom Schindl wrote:
                            >> pradeep kumar wrote:
                            >
                            >>>>Can you please elaborate on why apache filters can be an issue
                            > with the
                            >>>>autoflush problem that I noticed ?
                            >>>>
                            >>>>Also, I noticed that the autoflush work properly when I flush it to a
                            >>>>regular file. Its only when I choose STDOUT that the flushing gets
                            >>>>delayed. Is there some buffering that happens with STDOUT alone ?
                            > I am
                            >>>>confused if this is a modperl problem or an Apache problem.
                            >>>>
                            >
                            >
                            >> Well I guess that I read it a while ago but I'm not sure of. As
                            > far as I
                            >> understand the Apache2-Filter-System because a bucket is only sent to
                            >> the filter system after the BUFFER is full. But I really have no idea
                            >> what happens behind the scences after the print-call.
                            >
                            >> Maybe Stas, Geoff or someone else can look at this and tell you more.
                            >
                            >> Tom
                            -----BEGIN PGP SIGNATURE-----
                            Version: GnuPG v1.4.0 (GNU/Linux)
                            Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

                            iD8DBQFDQpqikVPeOFLgZFIRAtbPAJ92zeoQZ9varLcVyGRgXEIK5kJBiACeKJWT
                            Co6Ie/a0wN0sNMTioRnezPw=
                            =ft3W
                            -----END PGP SIGNATURE-----
                          Your message has been successfully submitted and would be delivered to recipients shortly.