user1642018
user1642018

Reputation:

Are these Both php - gzdecode functions same?

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;
}

Upvotes: 1

Views: 1215

Answers (1)

Jason Joseph Nathan
Jason Joseph Nathan

Reputation: 7601

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.

Upvotes: 1

Related Questions