title: Read / Write .gz file with PHP (method="PUT")
body: <p>I have code to read <code>json</code> file send to me via <code>method=PUT</code> (file.php)</p>
  
  <pre><code>&lt;?php
  $putdata = fopen( "php://input", "r" );  // to read/write json
  $fp = fopen( "myPut.json", "w" );
  while ( $data = fread( $putdata, 1024 ) )
       fwrite( $fp, $data );
  fclose( $fp );
  fclose( $putdata );
  ?&gt;
  </code></pre>
  
  <p>but I want as well read .gz version of above file i.e <code>192.168.1.20/example.json.gz</code></p>
  
  <p>I tried to handle this like below:</p>
  
  <pre><code>&lt;?php
  
  $gz_file = gzopen( "php://input", "rb" );
  $fp = fopen( "event.json.gz", "w+b" );
  while ( ! feof( $gz_file ) {
    fwrite( $fp, gzread( $gz_file, 2048 ) );
  }
  fclose( $fp );
  gzclose( $putdata );
  
  ?&gt;
  </code></pre>
  
  <p>but in wireshark I got :</p>
  
  <p><code>12081  89.736965987    192.168.1.30    192.168.1.20    HTTP    484 PUT /test/file.php HTTP/1.1</code></p>
  
  <p><code>12083  89.737075602    192.168.1.20    192.168.1.30    HTTP    251 HTTP/1.0 500 Internal Server Error</code></p>
  
  <h3>#</h3>
  
  <p>I would like to read this <code>.gz</code> file and save it. But it would be great If I could read gz file and fwrite it to other file like it happend for 1st example (myPut.json)</p>
  
  <p>It looks like I have some issue with feof/gzread func:</p>
  
  <pre><code>[Thu Nov 09 09:34:52.482566 2017] [:error] [pid 14253] [client 192.168.1.65:38302] PHP Warning:  feof() expects parameter 1 to be resource, boolean given in /var/www/html/test/file.php on line 29
  [Thu Nov 09 09:34:52.482570 2017] [:error] [pid 14253] [client 192.168.1.65:38302] PHP Warning:  gzread() expects parameter 1 to be resource, boolean given in /var/www/html/test/file.php on line 30
  [Thu Nov 09 09:34:52.482575 2017] [:error] [pid 14253] [client 192.168.1.65:38302] PHP Warning:  feof() expects parameter 1 to be resource, boolean given in /var/www/html/test/file.php on line 29
  [Thu Nov 09 09:34:52.482579 2017] [:error] [pid 14253] [client 192.168.1.65:38302] PHP Warning:  gzread() expects parameter 1 to be resource, boolean given in /var/www/html/test/file.php on line 30
  [Thu Nov 09 09:34:52.482583 2017] [:error] [pid 14253] [client 192.168.1.65:38302] PHP Warning:  feof() expects parameter 1 to be resource, boolean given in /var/www/html/test/file.php on line 29
  </code></pre>