1

i faced PHP: Call to undefined function gzdecode() error few days back so i have been using this in php

function gzdecode($data) 
{ 
   return gzinflate(substr($data,10,-8)); 
} 

ref: PHP: Call to undefined function gzdecode()

i found this old code snippet while looking in old php files , so can i use above code instead of this one ?

function gzdecode($data) {
  $g=tempnam('/tmp', 'php-gz');
  @file_put_contents($g, $data);
  ob_start();
  readgzfile($g);
  $d=ob_get_clean();
  unlink($g);
  return $d;
}
Community
  • 1
  • 1
  • Given that `gzinflate`, `gzdecode` and `readgzfile` are all from the Zlib PHP extension, I'd be very surprised if the original didn't work but either replacement did. – zneak Apr 22 '14 at 02:45
  • Why can't you use the built-in functions? Are you on an older PHP version? Upgrade. Do you not have ZLib extension installed? Install it. – Amal Murali Apr 22 '14 at 02:50

1 Answers1

1

If you have access to your php.ini, simply enable the zlib extension to use gzencode. Each compression method has some slight differences.

Please read an abstract of this answer https://stackoverflow.com/a/621987/382536 by @thomasrutter

All of these are usable. I would use gzencode() because it is self-contained; its output is the same as if you had used the gzip command line tool.

There is not really much difference between the three.

  • gzencode() uses the fully self-contained gzip format, same as the gzip command line tool
  • gzcompress() uses the raw ZLIB format. It is similar to gzencode but with less header data, etc. I think it was intended for streaming.
  • gzdeflate() uses the raw DEFLATE algorithm on its own, which is the basis for both the other formats.
Community
  • 1
  • 1
Jason J. Nathan
  • 7,422
  • 2
  • 26
  • 37
  • Its already enabled but still getting the error , thats why i had to sue this custom fucntion., thanks –  Apr 22 '14 at 03:43