Chunked encoding with php+apache2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jonathan.kleid@gmail.com

    Chunked encoding with php+apache2

    I'm trying to figure out how to enable chunked encoding with php over
    apache2 for a particular page. My php/apache combination definitely
    supports chunked encoding, because a page which calls only phpinfo()
    uses it. On the other hand, pages without phpinfo() don't get sent with
    chunked encoding (content-length is used instead). Does anyone know
    how to specifically enable chunked encoding for a given page?
    Thanks,
    Jon

  • Manuel Lemos

    #2
    Re: Chunked encoding with php+apache2

    on 02/02/2005 11:51 PM jonathan.kleid@ gmail.com said the following:[color=blue]
    > I'm trying to figure out how to enable chunked encoding with php over
    > apache2 for a particular page. My php/apache combination definitely
    > supports chunked encoding, because a page which calls only phpinfo()
    > uses it. On the other hand, pages without phpinfo() don't get sent with
    > chunked encoding (content-length is used instead). Does anyone know
    > how to specifically enable chunked encoding for a given page?[/color]

    Why do you want to force chunked encoding on pages that are not
    generated dynamically?

    Chunked encoding is only useful when you do not know in advance the page
    size.

    --

    Regards,
    Manuel Lemos

    PHP Classes - Free ready to use OOP components written in PHP
    Free PHP Classes and Objects 2025 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials


    PHP Reviews - Reviews of PHP books and other products


    Metastorage - Data object relational mapping layer generator

    Comment

    • jonathan.kleid@gmail.com

      #3
      Re: Chunked encoding with php+apache2

      > Why do you want to force chunked encoding on pages that are not[color=blue]
      > generated dynamically?
      >
      > Chunked encoding is only useful when you do not know in advance the[/color]
      page[color=blue]
      > size.[/color]

      The pages *are* created dynamically -- they're written in php, not
      plain html. The top part of the page is generated quickly, but the
      last part of the page is not generated until after a lengthy operation,
      which takes from 5-10 seconds. I need the top part of the page to
      display quickly, and then display the last bit later, when it's finally
      available. It seems to me that enabling chunked encoding, and flushing
      the output at appropriate times is the best (only?) way to accomplish
      this (without resorting to frames or complex Javascript). But extensive
      Google and documentation searching has yielded nothing for me, so far,
      as how to enable it.

      Comment

      • Daniel Tryba

        #4
        Re: Chunked encoding with php+apache2

        jonathan.kleid@ gmail.com wrote:[color=blue]
        > The pages *are* created dynamically -- they're written in php[/color]
        [snip][color=blue]
        > But extensive Google and documentation searching has yielded nothing
        > for me, so far, as how to enable it.[/color]

        But if a content-length header gets sent (like you suggest in the OP),
        something (either php or apache) is buffering output.

        Don't know of any ready made/easy way to turn on chunks. But you could
        write an outputbuffer handler that does (but you'd still be at mercy of
        Apaches buffering (and the client UAs buffering techniques)).

        Comment

        • jonathan.kleid@gmail.com

          #5
          Re: Chunked encoding with php+apache2

          > Don't know of any ready made/easy way to turn on chunks. But you
          could[color=blue]
          > write an outputbuffer handler that does (but you'd still be at mercy[/color]
          of[color=blue]
          > Apaches buffering (and the client UAs buffering techniques)).[/color]

          Thanks for the suggestion -- I actually tried that exact thing, but the
          content-length was still being sent along, in addition to the chunked
          encoding header that I manually added, via the header() function. If
          there was a way to control exactly which headers are sent, (i.e.
          suppress content-length from being sent) than this method would work,
          but I don't know if that's possible.

          Comment

          • jonathan.kleid@gmail.com

            #6
            Re: Chunked encoding with php+apache2

            >If there was a way to control exactly which headers are sent,[color=blue]
            > (i.e. suppress content-length from being sent) than this
            > method would work, but I don't know if that's possible.[/color]

            ....plus I'd need to find a way to disable buffering of the entire
            output. There's more to it than just disabling headers, I should have
            mentioned.

            Comment

            • Chung Leong

              #7
              Re: Chunked encoding with php+apache2

              <jonathan.kleid @gmail.com> wrote in message
              news:1107395487 .070568.231470@ g14g2000cwa.goo glegroups.com.. .[color=blue]
              > I'm trying to figure out how to enable chunked encoding with php over
              > apache2 for a particular page. My php/apache combination definitely
              > supports chunked encoding, because a page which calls only phpinfo()
              > uses it. On the other hand, pages without phpinfo() don't get sent with
              > chunked encoding (content-length is used instead). Does anyone know
              > how to specifically enable chunked encoding for a given page?
              > Thanks,
              > Jon
              >[/color]

              Chunking doesn't happen if a content-length header is present. From the
              source code:

              if ((r->connection->keepalive != AP_CONN_CLOSE)
              && ((r->status == HTTP_NOT_MODIFI ED)
              || (r->status == HTTP_NO_CONTENT )
              || r->header_only
              || apr_table_get(r->headers_out, "Content-Length")
              || ap_find_last_to ken(r->pool,
              apr_table_get(r->headers_out,
              "Transfer-Encoding"),
              "chunked")
              || ((r->proto_num >= HTTP_VERSION(1, 1))
              && (r->chunked = 1))) /* THIS CODE IS CORRECT, see above. */

              The variable chunked would not get set if any of the previous conditions are
              true. One of them being the presencce of a content-length header. Another,
              which might make you scratch your head, is the presence of
              "Thansfer-encoding: chunked".

              The Apache 2 output filter will automatically add a content-length header if
              it sees an end-of-stream marker AND nothing has been sent yet. From the
              source code:

              if (ctx->data_sent == 0 && eos) {
              ap_set_content_ length(r, r->bytes_sent);
              }

              If PHP passes any data down to Apache before it sends EOS, then chunking
              happens. PHP uses a output buffer of 4096 bytes by default. Any page smaller
              than that will not get chunked.


              Comment

              • jonathan.kleid@gmail.com

                #8
                Re: Chunked encoding with php+apache2

                > Chunking doesn't happen if a content-length header is present.[color=blue]
                > From the source code:[/color]

                Thanks very much for the help -- the apparent behavior makes a lot more
                sense now.

                Comment

                Working...