note 110817 modified in function.gzinflate by danbrown

From: Date: Tue, 11 Dec 2012 16:39:29 +0000
Subject: note 110817 modified in function.gzinflate by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192466@lists.php.net to get a copy of this message
Take care when using the optional second parameter $length! In our tests -at least in certain situations- we were unable to determine the actual use of this parameter, plus, it lead to the script either being unable to inflate compressed data or crash due to memory-problems. Example: When trying to inflate the compressed data from a website, we were literally unable to find a value (other than 0) for $length in order to make gzinflate work... while without the second parameter (or setting it to 0) gzinflate worked like a charm: <?php // ----------------------------------------------------------------------- // Test 1 works without problems. Memory peak usage: Before inflating: 24.787 kB; after: 24.844 kB. gzinflate( substr($deflated_body, 10) ); // ----------------------------------------------------------------------- // ALL three of the following tests failed with a warning. Memory peak usage: Before inflating: 24.787 kB; after: 298.262 kB. gzinflate( substr($deflated_body, 10), 200 * strlen($deflated_body) ); gzinflate( substr($deflated_body, 10), 32768 * strlen($deflated_body) ); gzinflate( substr($deflated_body, 10), 11000 ); gzinflate( substr($deflated_body, 10), 280000000 ); // the PHP memory limit was set to 300MB (memory_limit=300M) => Warning: gzinflate() [function.gzinflate]: insufficient memory in [...] // ----------------------------------------------------------------------- // The last test failed with a fatal error. Memory peak usage: Before inflating: 24.787 kB; after: ? (> 300M). gzinflate( substr($deflated_body, 10), 300000000 ); // the PHP memory limit was set to 300MB (memory_limit=300M) => Fatal error: Allowed memory size of 314572800 bytes exhausted (tried to allocate 300000000 bytes) in ?> In short: We were unable to determine the actual use of the second parameter in certain situations. Be careful with using the second parameter $length! --was-- Take care when using the optional second parameter $length! In our tests -at least in certain situations- we were unable to determine the actual use of this parameter, plus, it lead to the script either being unable to inflate compressed data or crash due to memory-problems. Example: When trying to inflate the compressed data from a website, we were literally unable to find a value (other than 0) for $length in order to make gzinflate work... while without the second parameter (or setting it to 0) gzinflate worked like a charm: Test-URL: http://www.jumptags.com/topic/kreiskolbenmotor/ Deflated Content-Length: 4150 Inflated Content-Length: 10870 <?php // ----------------------------------------------------------------------- // Test 1 works without problems. Memory peak usage: Before inflating: 24.787 kB; after: 24.844 kB. gzinflate( substr($deflated_body, 10) ); // ----------------------------------------------------------------------- // ALL three of the following tests failed with a warning. Memory peak usage: Before inflating: 24.787 kB; after: 298.262 kB. gzinflate( substr($deflated_body, 10), 200 * strlen($deflated_body) ); gzinflate( substr($deflated_body, 10), 32768 * strlen($deflated_body) ); gzinflate( substr($deflated_body, 10), 11000 ); gzinflate( substr($deflated_body, 10), 280000000 ); // the PHP memory limit was set to 300MB (memory_limit=300M) => Warning: gzinflate() [function.gzinflate]: insufficient memory in [...] // ----------------------------------------------------------------------- // The last test failed with a fatal error. Memory peak usage: Before inflating: 24.787 kB; after: ? (> 300M). gzinflate( substr($deflated_body, 10), 300000000 ); // the PHP memory limit was set to 300MB (memory_limit=300M) => Fatal error: Allowed memory size of 314572800 bytes exhausted (tried to allocate 300000000 bytes) in ?> In short: We were unable to determine the actual use of the second parameter in certain situations. Be careful with using the second parameter $length! http://php.net/manual/en/function.gzinflate.php

« previous php.notes (#192466) next »