Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.4 RN Issues
Author Message
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Fri Oct 21, 2011 6:29 am Reply with quote

You may find something using phpinfo();
Just create a php file with
Code:
phpinfo();
in it and navigate to the file in your browser.
 
View user's profile Send private message Send e-mail
webservant
Worker
Worker



Joined: Feb 26, 2006
Posts: 206
Location: Springfield, MA

PostPosted: Fri Oct 21, 2011 7:56 am Reply with quote

My server has these streams enabled:
https, ftps, compress.zlib, compress.bzip2, php, file, data, http, ftp, zip

With these registered stream filters:
zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed

But more importantly, it has (both server and evn):
HTTP_ACCEPT_ENCODING = gzip, deflate

So, if there is not a specific RN module that calls for compressing (e.g., download), then I suspect that the server configuration is compressing by mime type. Sound reasonable?

_________________
Awaiting His Shout
Webservant - GraciousCall.org
Romans 8:28-39 
View user's profile Send private message Visit poster's website AIM Address
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Sat Oct 22, 2011 9:35 am Reply with quote

See this line in the code you posted:

Code:


               if(ini_get('zlib.output_compression')) @ini_set('zlib.output_compression', 'Off'); // gzip compression can mess up the stream (content-length issue?)


I suspect your host is not allowing you to perform an ini_set. Just to test this theory, try removing your code changes and then also remove the "@" in front of the "ini_set" and also turn on $display_errors in config.php (to "true") just long enough to do one test and then see if there is an error message displayed.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
webservant







PostPosted: Sat Oct 22, 2011 10:12 am Reply with quote

Hmmm. I did not get an error, but I didn't trust it because it's just a popup dialog or a content-error. So, I put the line in a small script:

Code:
<html>

<html>
    <body>
       
<?php

echo 'compression = ' . ini_get('zlib.output_compression') . '\n';
@ini_set('zlib.output_compression', 'Off');
echo 'compression = ' . ini_get('zlib.output_compression') . '\n';

?>

    </body>
</html>


And I get this output:
Quote:
compression = \n
compression = \n


Oops - edited, my original post we incorrect.
 
montego







PostPosted: Sat Oct 22, 2011 10:17 am Reply with quote

You need to remove the "@" sign. That is going to suppress the error... Wink
 
webservant







PostPosted: Sat Oct 22, 2011 10:19 am Reply with quote

This:
Code:
<html>

    <body>
       
<?php

echo 'compression = ' . ini_get('zlib.output_compression') . '\n';
ini_set('zlib.output_compression', 'Off');
echo 'compression = ' . ini_get('zlib.output_compression') . '\n';

?>

    </body>
</html>


Give this output:
Quote:
compression = \n
Warning: ini_set() [ref.outcontrol]: Cannot change zlib.output_compression - headers already sent in /hermes/bosweb/web006/b64/ipw.gracious/public_html/dap2.php on line 7
compression = \n
 
webservant







PostPosted: Sat Oct 22, 2011 10:19 am Reply with quote

So, this is what you suspected.
 
montego







PostPosted: Sat Oct 22, 2011 10:55 am Reply with quote

No, not what I expected. The error you are seeing is because of the previous echo. Ok, try this. Put the code back in, but comment out the following line of code:

Code:


 if(ini_get('zlib.output_compression')) @ini_set('zlib.output_compression', 'Off'); // gzip compression can mess up the stream (content-length issue?)


But then add a line immediately following it with this code:

Code:


ini_set('zlib.output_compression', 'Off');


Then see if the web server adds the extra headers.
 
webservant







PostPosted: Sat Oct 22, 2011 11:14 am Reply with quote

I get a corrupted content error, but Fiddler tells me:

Fiddler has detected a protocol violation in session #3 (my request)
Content-Length mismatch: Response Header indicated (6,900,768 bytes), but server sent 6,732,879 bytes.

When I turn the friendly message off and do it again, I see two Content-Length headers one with the first value, and the second has the other value.

FF just give the Corrupted Content Error.
 
webservant







PostPosted: Sat Oct 22, 2011 11:16 am Reply with quote

Just to be clear, this is the code in go.php

Code:
            } else {


               // Download is hosted here, so go get it and stream it to the browser.

               // @todo Should improve configurability and/or bullet-proofness over time

//               if(ini_get('zlib.output_compression')) @ini_set('zlib.output_compression', 'Off'); // gzip compression can mess up the stream (content-length issue?)

ini_set('zlib.output_compression', 'Off');

               /*

                * Opera has an issue with MIME type of "octet-stream" and requires "octetstream" instead!

                */

               if (preg_match('#Opera(/| )([0-9].[0-9]{1,2})#i', getenv('HTTP_USER_AGENT'))) {

                  $cType = 'application/octetstream';

               } else {

                  $cType = 'application/octet-stream';

               }

               header('Content-Description: File Transfer');

               header('Content-Type: ' . $cType);

               header('Content-Disposition: attachment; filename="' . basename($lidinfo['url']) . '"');

               header('Content-Transfer-Encoding: binary');

               header('Expires: 0');

               header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

               header('Cache-Control: private', false);

               header('Pragma: public');

               header('Content-Length: ' . filesize($lidinfo['url']));

               // If output bufferring was used, need to ensure to clean it out

               @ob_clean();

               @flush();

               @set_time_limit(0); // May not be allowed or even desired, but choosing simple for first go-around

               readfile($lidinfo['url']); // Ok, go get it... and hope it doesn't consume all the PHP memory!

            }

            die();

         } else {

 
webservant







PostPosted: Sat Oct 22, 2011 11:31 am Reply with quote

BTW:

Code:
<?php print_r(ini_get_all("zlib")); ?>


Gives:
Quote:
Array ( [zlib.output_compression] => Array ( [global_value] => [local_value] => [access] => 7 ) [zlib.output_compression_level] => Array ( [global_value] => -1 [local_value] => -1 [access] => 7 ) [zlib.output_handler] => Array ( [global_value] => [local_value] => [access] => 7 ) )
 
webservant







PostPosted: Sat Oct 22, 2011 11:34 am Reply with quote

And my phpinfo output reports:

ZLib Support enabled
Stream Wrapper support compress.zlib://
Stream Filter support zlib.inflate, zlib.deflate
Compiled Version 1.2.3.3
Linked Version 1.2.3.4

Directive Local Value Master Value
zlib.output_compression Off Off
zlib.output_compression_level -1 -1
zlib.output_handler no value no value

SO - if the value is already Off ...
From where is the second content-length coming?
 
montego







PostPosted: Sat Oct 22, 2011 12:22 pm Reply with quote

I wonder if somehow this code in mainfile.php is turning it on:

Code:


} elseif ($phpver > '4.0' && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && !empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
    if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
        if (extension_loaded('zlib')) {
            $do_gzip_compress = true;
            ob_start(array('ob_gzhandler',5));
            ob_implicit_flush(0);
            if (ereg('MSIE', $_SERVER['HTTP_USER_AGENT'])) {
                header('Content-Encoding: gzip');
            }
        }
    }
}


I wonder if that somehow that last if needs to be commented out...
 
webservant







PostPosted: Sat Oct 22, 2011 2:25 pm Reply with quote

Yes! That is the code interaction!!

When I put go.php back to the original, and make mainfile.php like this:

Code:
} elseif ($phpver > '4.0' && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && !empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {

//   if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
//      if (extension_loaded('zlib')) {
//         $do_gzip_compress = true;
//         ob_start(array('ob_gzhandler',5));
//         ob_implicit_flush(0);
//         if (ereg('MSIE', $_SERVER['HTTP_USER_AGENT'])) {
//            header('Content-Encoding: gzip');
//         }
//      }
//   }
}


I do not get the error!

This is because my web hosting company has this in the php configuration:

HTTP_ACCEPT_ENCODING gzip, deflate
 
montego







PostPosted: Sat Oct 22, 2011 2:33 pm Reply with quote

I'll have to see if I can somehow test for this although I find it weird that it works on my site. I still can't figure that out as to why. I think that code is there for the forums purposes, at least that is the only place where that $do_gzip_compress variable is used. I might be able to destroy the buffer...

Can someone out there with more knowledge on this subject shed more light on this for us? It is not my area of expertise for sure. Just following the breadcrumbs thus far...

Guess what I/we need to know is what that code is doing and whether it is ok to strip out.
 
montego







PostPosted: Sat Oct 22, 2011 2:37 pm Reply with quote

Something was bothering too with the code. Lets try putting that mainfile.php code back and do this instead. Take all of this code here:

Code:


            } else {
               // Download is hosted here, so go get it and stream it to the browser.
               // @todo Should improve configurability and/or bullet-proofness over time
               if(ini_get('zlib.output_compression')) @ini_set('zlib.output_compression', 'Off'); // gzip compression can mess up the stream (content-length issue?)
               /*
                * Opera has an issue with MIME type of "octet-stream" and requires "octetstream" instead!
                */
               if (preg_match('#Opera(/| )([0-9].[0-9]{1,2})#i', getenv('HTTP_USER_AGENT'))) {
                  $cType = 'application/octetstream';
               } else {
                  $cType = 'application/octet-stream';
               }
               header('Content-Description: File Transfer');
               header('Content-Type: ' . $cType);
               header('Content-Disposition: attachment; filename="' . basename($lidinfo['url']) . '"');
               header('Content-Transfer-Encoding: binary');
               header('Expires: 0');
               header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
               header('Cache-Control: private', false);
               header('Pragma: public');
               header('Content-Length: ' . filesize($lidinfo['url']));
               // If output bufferring was used, need to ensure to clean it out
               @ob_clean();
               @flush();
               @set_time_limit(0); // May not be allowed or even desired, but choosing simple for first go-around
               readfile($lidinfo['url']); // Ok, go get it... and hope it doesn't consume all the PHP memory!
            }


and instead, replace it with this:

Code:


            } else {
               // Download is hosted here, so go get it and stream it to the browser.
               // @todo Should improve configurability and/or bullet-proofness over time
               if(ini_get('zlib.output_compression')) @ini_set('zlib.output_compression', 'Off'); // gzip compression can mess up the stream (content-length issue?)
               /*
                * Opera has an issue with MIME type of "octet-stream" and requires "octetstream" instead!
                */
               if (preg_match('#Opera(/| )([0-9].[0-9]{1,2})#i', getenv('HTTP_USER_AGENT'))) {
                  $cType = 'application/octetstream';
               } else {
                  $cType = 'application/octet-stream';
               }
               // If output bufferring was used, need to ensure to clean it out
               @ob_clean();
               @flush();
               header('Content-Description: File Transfer');
               header('Content-Type: ' . $cType);
               header('Content-Disposition: attachment; filename="' . basename($lidinfo['url']) . '"');
               header('Content-Transfer-Encoding: binary');
               header('Expires: 0');
               header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
               header('Cache-Control: private', false);
               header('Pragma: public');
               header('Content-Length: ' . filesize($lidinfo['url']));
               @set_time_limit(0); // May not be allowed or even desired, but choosing simple for first go-around
               readfile($lidinfo['url']); // Ok, go get it... and hope it doesn't consume all the PHP memory!
            }


I can't recall when the headers actually get sent, if its immediate or only after the first output is generated. I just decided to move up the ob_clean() and ob_flush() ahead of the headers. Just curious if that works properly.
 
webservant







PostPosted: Sat Oct 22, 2011 3:02 pm Reply with quote

When I try my fix with a regular mainfile.php, it works and I get:
Content-Length: 6732879

When I try my fix with the gzip commented out in mainfile.php, it works and I get:
Content-Length: 6900768


When I try your patch with a regular mainfile.php, it gives the Corrupted Content error and I get:
Content-Length: 6900768
Content-Length: 6732879

When I try your patch with a regular mainfile.php, it works and I get:
Content-Length: 6900768
Content-Length: 6900768
 
montego







PostPosted: Sat Oct 22, 2011 6:27 pm Reply with quote

webservant, I'm confused on the last two as they seem the same but one works and the other doesn't?
 
webservant







PostPosted: Sat Oct 22, 2011 7:00 pm Reply with quote

The Corrupted Content error in FF 7.0.1 is triggered by multiple dis-agreeing Content-Length tags. I can see the data because I'm forcing the traffic through Fiddler which is watching the interaction of the browser and the web server at the network layer. The dual tags come back in each case, but FF only throws up when they don't say the same thing.
 
montego







PostPosted: Sat Oct 22, 2011 7:16 pm Reply with quote

What I am referring to is these two seem to contradict (please read carefully):

Quote:

When I try your patch with a regular mainfile.php, it gives the Corrupted Content error and I get:
Content-Length: 6900768
Content-Length: 6732879

When I try your patch with a regular mainfile.php, it works and I get:
Content-Length: 6900768
Content-Length: 6900768


I can't really tell what you did different to get different results.
 
webservant







PostPosted: Sat Oct 22, 2011 7:53 pm Reply with quote

The mainfile.php is original. One of the Content-Lengths comes from go.php - this line:

Code:
header('Content-Length: ' . filesize($lidinfo['url']));


The other must be from whatever is doing the gzip which results in a smaller file size.
 
Guardian2003







PostPosted: Sun Oct 23, 2011 1:05 am Reply with quote

I had suspected that it might have been the ob_start() and flush in go.php as it seems to come after the header send or atleast seems to come after header(....); in the logic flow BUT I'm basing that on on an assumption based purely on the code snips posted.

I believe the gzip compression routine in mainfile could be redundant and was primarily for the forums (as mentioned by M) , however, if you turn on gzip compression in the forum configuration you'll probably get a similar error, or at the very least a 'headers already sent' error.

What still puzzles me is why it only seems to affect your website and it appears that might be due to your host forcing some sort of HTTP compression be default.
 
webservant







PostPosted: Sun Oct 23, 2011 4:47 am Reply with quote

I'm not sure if it is that my host "forces" compression as much as the configuration allows compression and the RN code takes advantage of it when it is available. And there are five conditions that must be met for this to happen as seen in mainfile.php:

Code:
} elseif ($phpver > '4.0' && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && !empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {

   if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
      if (extension_loaded('zlib')) {
         $do_gzip_compress = true;
         ob_start(array('ob_gzhandler',5));
         ob_implicit_flush(0);
         if (ereg('MSIE', $_SERVER['HTTP_USER_AGENT'])) {
            header('Content-Encoding: gzip');
         }
      }
   }
}


In general, compression is a good thing because it can greatly reduce the packet size traversing the network. It puts a performance burden on the server and the browser, but can really speed up the communication on a slow connection.

With respect to why my server and not yours is really a question of whether or not your host meets the five conditions above....
 
montego







PostPosted: Sun Oct 23, 2011 8:55 am Reply with quote

webservant wrote:
The mainfile.php is original. One of the Content-Lengths comes from go.php - this line:

Code:
header('Content-Length: ' . filesize($lidinfo['url']));


The other must be from whatever is doing the gzip which results in a smaller file size.


Ok, so with mainfile.php being original which version of go.php works and which version does not? That is what I am trying to get at since you say on one hand this:

"it gives the Corrupted Content error and I get"

then you say the exact opposite here:

"it works and I get"

so I'm trying to get from you which one actually worked.
 
webservant







PostPosted: Sun Oct 23, 2011 11:40 am Reply with quote

Let me attempt to be clearer:

With this change in the original go.php (not the new IF stmt):

Code:
            } else {

               // Download is hosted here, so go get it and stream it to the browser.
               // @todo Should improve configurability and/or bullet-proofness over time
               if(ini_get('zlib.output_compression')) @ini_set('zlib.output_compression', 'Off'); // gzip compression can mess up the stream (content-length issue?)
               /*
                * Opera has an issue with MIME type of "octet-stream" and requires "octetstream" instead!
                */
               if (preg_match('#Opera(/| )([0-9].[0-9]{1,2})#i', getenv('HTTP_USER_AGENT'))) {
                  $cType = 'application/octetstream';
               } else {
                  $cType = 'application/octet-stream';
               }
               header('Content-Description: File Transfer');
               header('Content-Type: ' . $cType);
               header('Content-Disposition: attachment; filename="' . basename($lidinfo['url']) . '"');
               header('Content-Transfer-Encoding: binary');
               header('Expires: 0');
               header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
               header('Cache-Control: private', false);
               header('Pragma: public');

               // Fix to allow for mainfile.php setting either no compress or gzip compression
               if ($phpver > '4.0' && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && extension_loaded('zlib')) {
               } else {
               header('Content-Length: ' . filesize($lidinfo['url']));   
               }
               // End of compression fix

               // If output bufferring was used, need to ensure to clean it out
               @ob_clean();
               @flush();
               @set_time_limit(0); // May not be allowed or even desired, but choosing simple for first go-around
               readfile($lidinfo['url']); // Ok, go get it... and hope it doesn't consume all the PHP memory!
            }
            die();
         } else {


I get this one header with the original unaltered mainfile.php:
Content-Length: 6732879

and this one header with the mainfile.php that has the commented out gzip IF statement:
Content-Length: 6900768


On the other hand, if I replace this entire ELSE clause with your code like this:

Code:
            } else {

               // Download is hosted here, so go get it and stream it to the browser.
               // @todo Should improve configurability and/or bullet-proofness over time
               if(ini_get('zlib.output_compression')) @ini_set('zlib.output_compression', 'Off'); // gzip compression can mess up the stream (content-length issue?)
               /*
                * Opera has an issue with MIME type of "octet-stream" and requires "octetstream" instead!
                */
               if (preg_match('#Opera(/| )([0-9].[0-9]{1,2})#i', getenv('HTTP_USER_AGENT'))) {
                  $cType = 'application/octetstream';
               } else {
                  $cType = 'application/octet-stream';
               }
               // If output bufferring was used, need to ensure to clean it out
               @ob_clean();
               @flush();
               header('Content-Description: File Transfer');
               header('Content-Type: ' . $cType);
               header('Content-Disposition: attachment; filename="' . basename($lidinfo['url']) . '"');
               header('Content-Transfer-Encoding: binary');
               header('Expires: 0');
               header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
               header('Cache-Control: private', false);
               header('Pragma: public');
               header('Content-Length: ' . filesize($lidinfo['url']));
               @set_time_limit(0); // May not be allowed or even desired, but choosing simple for first go-around
               readfile($lidinfo['url']); // Ok, go get it... and hope it doesn't consume all the PHP memory!
            }
        die();
} else {


I get these two conflicting headers with the original unaltered mainfile.php which causes FF to display a Corrupted Content Error:
Content-Length: 6732879
Content-Length: 6900768

and these two identical headers with the mainfile.php that has the commented out gzip IF statement:
Content-Length: 6900768
Content-Length: 6900768

When I get two identical headers, FF does not throw an error even though there should only be one tag.


Bottom line - the change in go.php must not write a content-length header if compression is enabled through mainfile.php (because the compression will automatically add this header). Your fix (the second in this one) does not achieve this. This line of code:

Code:
 header('Content-Length: ' . filesize($lidinfo['url']));


needs to be conditionally written - only when gzip is not enabled.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.4 RN Issues

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©