title: Which compression method to use in PHP?
body: <p>I have a large amount of data to move using two PHP scripts: one on the client side using a command line PHP script and other behind Apache. I POST the data to the server side and use php://input stream to save it on the web-server end. To prevent from reaching any memory limits, data is separated into 500kB chunks for each POST request. All this works fine. </p>
  
  <p>Now, to save the bandwidth and speed it up, I want to compress the data before sending and decompress when received on the other end. I found 3 pairs of functions that can do the job, but I cannot decide which one to use:</p>
  
  <ul>
  <li><a href="http://php.net/manual/en/function.gzencode.php" rel="noreferrer"><code>gzencode</code></a> / <a href="http://php.net/manual/en/function.gzdecode.php" rel="noreferrer"><code>gzdecode</code></a></li>
  <li><a href="http://php.net/manual/en/function.gzdeflate.php" rel="noreferrer"><code>gzdeflate</code></a> / <a href="http://php.net/manual/en/function.gzinflate.php" rel="noreferrer"><code>gzinflate</code></a></li>
  <li><a href="http://php.net/manual/en/function.gzcompress.php" rel="noreferrer"><code>gzcompress</code></a> / <a href="http://php.net/manual/en/function.gzuncompress.php" rel="noreferrer"><code>gzuncompress</code></a></li>
  </ul>
  
  <p>Which pair of functions would you recommend and why?</p>
  
  <p><strong>UPDATE:</strong> I just read zlib FAQ:</p>
  
  <p><em>The gzip format (<code>gzencode</code>) was designed to retain the directory information about a single file, such as the name and last modification date. The zlib format (<code>gzcompress</code>) on the other hand was designed for in-memory and communication channel applications, and has a much more compact header and trailer and uses a faster integrity check than gzip.</em></p>