I just reworded (see below), and also I improved code slightly. Note
that, currently, my previous note shows. I assume that will change
soon.
Note:
The code below illustrates usage of the second parameter, in particular to
protect against fatal out-of-memory errors. It outputs:
1000000
1000000
error
Tested with PHP 5.3 on 32bit Linux.
<?php
function tryToGzinflate($deflatedData, $maxLen = 0) {
$data = gzinflate($deflatedData, $maxLen);
if ($data === false)
echo 'error<br>';
else
echo strlen($data).'<br>';
}
// random data:
$data = '';
for ($i = 0; $i < 1000000; $i++)
$data .= chr(mt_rand(97, 122)); // a-z
$deflatedData = gzdeflate($data);
ini_set('memory_limit', '5M'); // plenty of memory
tryToGzinflate($deflatedData);
tryToGzinflate($deflatedData, strlen($data));
ini_set('memory_limit', '100'); // little memory
tryToGzinflate($deflatedData, 100);
tryToGzinflate($deflatedData); // causes fatal out-of-memory error
--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php