I use code
<?php
$Str="Hello world!";
for ( $i = 0; $i < strlen($Str); $i++ ){
print $Str{$i};
}

and when i catch IP packets I found this

48 0d 0a 31 0d 0a - H ...1...
65 0d 0a 31 0d 0a - e ..1....
6c 0d 0a 31 0d 0a - l ...1...
6c 0d 0a 31 0d 0a - l ..1....
6f 0d 0a 31 0d 0a - o ..1....
20 0d 0a 31 0d 0a - ...1...
77 0d 0a 31 0d 0a - w ..1....
6f 0d 0a 31 0d 0a - o ..1....
72 0d 0a 31 0d 0a - r ..1....
6c 0d 0a 31 0d 0a - l ..1....
64 0d 0a 31 0d 0a - d ..1....
21 0d 0a 30 0d 0a 0d 0a - ! ..0....

Very strange, there are no octets 0d 0a 31 0d 0a and i dont send them to output stream.

But in browser is correct text printed
Hello world!

How to avoid outputting 0d 0a 31 0d 0a octets?

But if I use
<?php
$Str="Hello world!";
print $Str{$i};
}

anyway at the end
0d 0a 30 0d 0a 0d 0a
How to avoid outputting this octets?
Thanks.

    Those octets are the chunk-size parts of a chunked transfer encoding. In your case every character is transferd as one chunk. Which browser and web server do you have ?

    Thomas

      I use
      httpd-2.0.49
      and
      php-4.3.4
      on RedHat 9

        Ok,

        which browser do you use. Is set output_buffering set to Off or On or to a numeric value ?

        Is some kind of output compression enabled ?

        Thomas

          I use IE 6, but it not depends on browser. I check it with MyIE and also use WAP gate as http client. All sniffed packets the same.

            And which values do output_buffering and the other options mentioned in my last post have ?

            Thomas

              Where can i find output_buffering parameter. How can i change it?

                Create a script containing

                <?PHP
                phpinfo();
                ?>

                That prints some PHP info including buffering settings, supported extensions and stuff like that.

                Thomas

                  output_buffering is 1 in my case

                    Change it to e.g. 4096 or On (or Off if you don't want it at all) but not 1. I think having 1 causes PHP to transmit chunks with a size of 1 byte which is not the best setting.

                    Restart the web server after making the changes.

                    Setting output_buffering to Off might break scripts that rely on output_buffering being set to On (e.g. scripts that have output prior to any header function calls).

                    Thomas

                      phpinfo()
                      shows me values of output_buffering
                      Local Value = 1
                      Master Value = no value

                      if i change in php.ini output_buffering = 4096 i get
                      Local Value = 1
                      Master Value = 4096

                      and script
                      <?php
                      $Str="Hello world!";
                      for ( $i = 0; $i < strlen($Str); $i++ ){
                      print $Str{$i};
                      }

                      resul the same, with octets

                        Hmmm .... for some reason the local value is still 1. Do you have custom output_buffering settings in the httpd.conf for the given VirtualHost (if configured as VirtualHost at all) or do you have a .htaccess file that contains output_buffering settings ?

                        Thomas

                          Yes, in httpd.conf there was
                          php_flag output_buffering On
                          I comment this and use in php.ini
                          1. output_buffering = Off
                          2. output_buffering = 4096

                          Now the Local Value and Master Value changed, but anyway there are unusable octets in IP packets

                            I also comment
                            #php_value output_hendler mb_output_hendler
                            #php_value default_charset Shift_JIS

                            and set
                            output_buffering = 4096

                            and there no more
                            0d 0a 31 0d 0a octets
                            but at the end there are anyway 0d 0a 30 0d 0a 0d 0a

                            Is it possible to delete this octets to

                            Thanks

                              No,

                              not if you enabled HTTP/1.1 support in your browser (default and recommended I think).

                              PHP and Apache use chunked encoding as default Transfer-Encoding. The octets you posted are the last chunk header (which contains the info chunk size 0) that tells the browser that this is the end of the content. There's no need to worry about that, it's just the standard.

                              You can disable HTTP/1.1 support at least in IE (it's an option in the settings). If you disable HTTP/1.1 you shouldn't get any chunked data but I don't see a reason to do that.

                              I think the most important thing was to increase the chunk size because a chunk size of 1 can decrease perfomance noticeably.

                              Thomas

                                Write a Reply...