How to remove blanks at runtime??

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

    #1

    How to remove blanks at runtime??

    Is there any way to remove automatically all blank chars from the html
    sent to the client??

    Example:
    ----------------------------------------------------------------
    <?
    echo "HTML tags here<br>" ;
    ?>
    more HTML here
    <div>
    <div>
    Some text
    </div>
    </div>

    <?
    ----------------------------------------------------------------

    after running this php script the client should receive:
    ----------------------------------------------------------------
    HTML tags here<br>
    more HTML here
    <div>
    <div>
    Some text
    </div>
    </div>
    ----------------------------------------------------------------

    Is there any option in PHP to do this automatically??

    Thanks in advance.

  • Andy Hassall

    #2
    Re: How to remove blanks at runtime??

    On 7 Oct 2006 14:51:36 -0700, Hermann.Richter @gmail.com wrote:
    >Is there any way to remove automatically all blank chars from the html
    >sent to the client??
    >
    >Example:
    >----------------------------------------------------------------
    ><?
    >echo "HTML tags here<br>" ;
    >?>
    >more HTML here
    ><div>
    > <div>
    > Some text
    > </div>
    ></div>
    >
    ><?
    >----------------------------------------------------------------
    >
    >after running this php script the client should receive:
    >----------------------------------------------------------------
    >HTML tags here<br>
    >more HTML here
    ><div>
    ><div>
    >Some text
    ></div>
    ></div>
    >----------------------------------------------------------------
    >
    >Is there any option in PHP to do this automatically??
    Not built-in, but you could use output buffering and modify the contents of
    the buffer as it's output.



    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Hermann.Richter@gmail.com

      #3
      Re: How to remove blanks at runtime??

      Thanks.

      Is there any performance impact or server overloading if I use output
      buffering??

      Does it take more resources (cpu, ram)??



      On Oct 7, 6:59 pm, Andy Hassall <a...@andyh.co. ukwrote:
      On 7 Oct 2006 14:51:36 -0700, Hermann.Rich... @gmail.com wrote:
      >
      >
      >
      >
      >
      Is there any way to remove automatically all blank chars from the html
      sent to the client??
      >
      Example:
      ----------------------------------------------------------------
      <?
      echo "HTML tags here<br>" ;
      ?>
      more HTML here
      <div>
      <div>
      Some text
      </div>
      </div>
      >
      <?
      ----------------------------------------------------------------
      >
      after running this php script the client should receive:
      ----------------------------------------------------------------
      HTML tags here<br>
      more HTML here
      <div>
      <div>
      Some text
      </div>
      </div>
      ----------------------------------------------------------------
      >
      Is there any option in PHP to do this automatically?? Not built-in, but you could use output buffering and modify the contents of
      the buffer as it's output.
      >

      >
      --
      Andy Hassall :: a...@andyh.co.u k ::http://www.andyh.co.ukhttp://www.and....co.uk/space:: disk and FTP usage analysis tool- Hide quoted text -- Show quoted text -

      Comment

      • Peter Fox

        #4
        Re: How to remove blanks at runtime??

        Following on from 's message. . .
        >Thanks.
        >
        >Is there any performance impact or server overloading if I use output
        >buffering??
        >
        >Does it take more resources (cpu, ram)??
        No there is absolutely no overhead when buffering and processing the
        buffer. Why should that be? It's not as if you're using RAM or CPU
        cycles.



        If you're generating the output dynamically then clear out those spaces
        in the source code.

        If you are just serving HTML then tidy up the original HTML once.


        --
        PETER FOX Not the same since the e-commerce business came to a .
        peterfox@eminen t.demon.co.uk.n ot.this.bit.no. html
        2 Tees Close, Witham, Essex.
        Gravity beer in Essex <http://www.eminent.dem on.co.uk>

        Comment

        • Jerry Stuckle

          #5
          Re: How to remove blanks at runtime??

          Peter Fox wrote:
          Following on from 's message. . .
          >
          >Thanks.
          >>
          >Is there any performance impact or server overloading if I use output
          >buffering??
          >>
          >Does it take more resources (cpu, ram)??
          >
          No there is absolutely no overhead when buffering and processing the
          buffer. Why should that be? It's not as if you're using RAM or CPU
          cycles.
          >
          >
          >
          If you're generating the output dynamically then clear out those spaces
          in the source code.
          >
          If you are just serving HTML then tidy up the original HTML once.
          >
          >
          Actually, there is a slight performance hit, but it isn't much.

          PHP will by default buffer the output, But this is not a huge buffer(I
          forget the size),and when it fills, the output is sent to the web server.

          If you use output buffering, all the output is buffered until you send
          the data on. This will generally require more RAM for the larger
          buffer, and more CPU cycles to process the buffer.

          But it's not a great amount unless you have large pages.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Hermann.Richter@gmail.com

            #6
            Re: How to remove blanks at runtime??

            My pages are not too big. But I'm expecting to receive a lot amount of
            visits so I'm very concerned about performance because a slight
            overhead in processing a page could have a big impact on the server
            when serving hundreds of requests per second.

            What do you think??
            Could there be a noticeable impact in server's performance on a very
            visited site??

            Thank you all for your replies.


            On Oct 9, 9:21 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
            Peter Fox wrote:
            Following on from 's message. . .
            >
            Thanks.
            >
            Is there any performance impact or server overloading if I use output
            buffering??
            >
            Does it take more resources (cpu, ram)??
            >
            No there is absolutely no overhead when buffering and processing the
            buffer. Why should that be? It's not as if you're using RAM or CPU
            cycles.
            >
            If you're generating the output dynamically then clear out those spaces
            in the source code.
            >
            If you are just serving HTML then tidy up the original HTML once.Actually, there is a slight performance hit, but it isn't much.
            >
            PHP will by default buffer the output, But this is not a huge buffer(I
            forget the size),and when it fills, the output is sent to the web server.
            >
            If you use output buffering, all the output is buffered until you send
            the data on. This will generally require more RAM for the larger
            buffer, and more CPU cycles to process the buffer.
            >
            But it's not a great amount unless you have large pages.
            >
            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstuck...@attgl obal.net
            =============== ===- Hide quoted text -- Show quoted text -

            Comment

            • Jerry Stuckle

              #7
              Re: How to remove blanks at runtime??

              Hermann.Richter @gmail.com wrote:
              On Oct 9, 9:21 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
              >
              >>Peter Fox wrote:
              >>
              >>>Following on from 's message. . .
              >>
              >>>>Thanks.
              >>
              >>>>Is there any performance impact or server overloading if I use output
              >>>>buffering ??
              >>
              >>>>Does it take more resources (cpu, ram)??
              >>
              >>>No there is absolutely no overhead when buffering and processing the
              >>>buffer. Why should that be? It's not as if you're using RAM or CPU
              >>>cycles.
              >>
              >>>If you're generating the output dynamically then clear out those spaces
              >>>in the source code.
              >>
              >>>If you are just serving HTML then tidy up the original HTML once.Actually, there is a slight performance hit, but it isn't much.
              >>
              >>PHP will by default buffer the output, But this is not a huge buffer(I
              >>forget the size),and when it fills, the output is sent to the web server.
              >>
              >>If you use output buffering, all the output is buffered until you send
              >>the data on. This will generally require more RAM for the larger
              >>buffer, and more CPU cycles to process the buffer.
              >>
              >>But it's not a great amount unless you have large pages.
              >>
              >
              My pages are not too big. But I'm expecting to receive a lot amount of
              visits so I'm very concerned about performance because a slight
              overhead in processing a page could have a big impact on the server
              when serving hundreds of requests per second.
              >
              What do you think??
              Could there be a noticeable impact in server's performance on a very
              visited site??
              >
              Thank you all for your replies.
              >
              (Top posting fixed)

              Yes, it can affect performance. The reason being that if you don't use
              output buffering, PHP can send data to the web server (and onto the
              client) while the page is being built. As soon as a buffer gets full,
              PHP sends it to the web server; the web server may send it immediately
              or buffer it further, but eventually it will send it to the client.

              Using the output buffering functions means PHP will have to buffer
              everything, then later send everything to the web server at once. Then
              the web server sends it to the client.

              So not only does this take more memory, it slows things down because PHP
              and the web server cannot pick the most opportune times to pass the data on.

              With all of that - normally it's not a significant delay, however.


              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Peter Fox

                #8
                Re: How to remove blanks at runtime??

                Following on from Jerry Stuckle's message. . .

                [Top posting to annoy dimwits who can't cope with posting wherever is
                most appropriate.]

                You failed to answer the OP's question. He wants to know _exactly_, in
                numbers and based on things like 'a lot' what the performance hit will
                be. You've had two tries at it - strangely without success: Any reason
                for that failure do you think?
                >
                >(Top posting fixed)
                [But you didn't think of snipping - Duh! - Repeat after me: "Threaded
                newsreader"]
                >
                >Yes, it can affect performance. The reason being that if you don't use
                >output buffering, PHP can send data to the web server (and onto the
                >client) while the page is being built. As soon as a buffer gets full,
                >PHP sends it to the web server; the web server may send it immediately
                >or buffer it further, but eventually it will send it to the client.
                >
                >Using the output buffering functions means PHP will have to buffer
                >everything, then later send everything to the web server at once. Then
                >the web server sends it to the client.
                >
                >So not only does this take more memory, it slows things down because PHP
                >and the web server cannot pick the most opportune times to pass the data on.
                >
                >With all of that - normally it's not a significant delay, however.
                >
                >
                --
                PETER FOX Not the same since the statuette business went bust
                peterfox@eminen t.demon.co.uk.n ot.this.bit.no. html
                2 Tees Close, Witham, Essex.
                Gravity beer in Essex <http://www.eminent.dem on.co.uk>

                Comment

                • Andy Hassall

                  #9
                  Re: How to remove blanks at runtime??

                  On 9 Oct 2006 17:06:32 -0700, Hermann.Richter @gmail.com wrote:
                  >My pages are not too big. But I'm expecting to receive a lot amount of
                  >visits so I'm very concerned about performance because a slight
                  >overhead in processing a page could have a big impact on the server
                  >when serving hundreds of requests per second.
                  >
                  >What do you think??
                  >Could there be a noticeable impact in server's performance on a very
                  >visited site??
                  Perhaps it's worth stepping back a little and asking what is your goal here -
                  why do you want to remove the whitespace?

                  If the main goal is to reduce the amount of data transferred from server to
                  client, you may be better off using output compression (e.g. setting
                  zlib.output_com pression to On or a value for the buffer size). Not only will
                  this compress the whitespace down, it'll transparently compress all the other
                  text as well. Reductions of 10:1 for the amount of data transferred are not
                  uncommon. And as this is done in a compiled library then it will likely fare
                  well compared with doing string processing in PHP to remove whitespace.

                  But perhaps you have another reason, so it may be useful to hear it.

                  --
                  Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
                  http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: How to remove blanks at runtime??

                    Peter Fox wrote:
                    Following on from Jerry Stuckle's message. . .
                    >
                    [Top posting to annoy dimwits who can't cope with posting wherever is
                    most appropriate.]
                    >
                    You failed to answer the OP's question. He wants to know _exactly_, in
                    numbers and based on things like 'a lot' what the performance hit will
                    be. You've had two tries at it - strangely without success: Any reason
                    for that failure do you think?
                    >
                    >>
                    >(Top posting fixed)
                    >
                    [But you didn't think of snipping - Duh! - Repeat after me: "Threaded
                    newsreader"]
                    >
                    Poor troll doesn't follow conventions.

                    I didn't answer exactly because there is no exact answer - which you
                    would know if you had any understanding of systems and how PHP and
                    Apache work.

                    It depends on too many things. CPU speed, amount of available memory,
                    PHP and Apache options, size of pages being buffered, number of pages
                    being buffered, even ping times and link speed on the client end.

                    And a whole bunch more.

                    But I repeat - for most systems it should not be a significant slowdown.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • Hermann.Richter@gmail.com

                      #11
                      Re: How to remove blanks at runtime??

                      Thank you, Andy and Jerry.

                      My reasons to remove blanks chars (\n, \r, \t, space) are basicly that
                      I want to reduce bandwidth usage and to add some kind of obfuscation to
                      my codes.

                      I think that the zlib.compressio n thing will do it for the bandwidth
                      usage.
                      For the obfuscation, I think I still will have to use output buffering.



                      Jerry Stuckle wrote:
                      Peter Fox wrote:
                      Following on from Jerry Stuckle's message. . .

                      [Top posting to annoy dimwits who can't cope with posting wherever is
                      most appropriate.]

                      You failed to answer the OP's question. He wants to know _exactly_, in
                      numbers and based on things like 'a lot' what the performance hit will
                      be. You've had two tries at it - strangely without success: Any reason
                      for that failure do you think?
                      >
                      (Top posting fixed)
                      [But you didn't think of snipping - Duh! - Repeat after me: "Threaded
                      newsreader"]
                      >
                      Poor troll doesn't follow conventions.
                      >
                      I didn't answer exactly because there is no exact answer - which you
                      would know if you had any understanding of systems and how PHP and
                      Apache work.
                      >
                      It depends on too many things. CPU speed, amount of available memory,
                      PHP and Apache options, size of pages being buffered, number of pages
                      being buffered, even ping times and link speed on the client end.
                      >
                      And a whole bunch more.
                      >
                      But I repeat - for most systems it should not be a significant slowdown.
                      >
                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      Working...