Membership is FREE – with unlimited access to all features, tools, and discussions. Premium accounts get benefits like banner ads and newsletter exposure. ✅ Signature links are now free for all. 🚫 No AI-generated (LLM) posts allowed. Share your own thoughts and experience — accounts may be terminated for violations.

Is there a PHP / Gzip guru?

Status
Not open for further replies.
Joined
May 31, 2007
Posts
2,092
Reaction score
179
I'm pulling a gzipped xml file from a remote web site (all OK), when I open this with gzopen and stuff it into simplexml_load_string it fails with an incomplete read.

I've changed the code about to exec "gzip -d myxml.gz" and this still fails to produce a full valid XML file

The php exec returns

gzip: /tmp/myxml.gz: unexpected end of file

However, if I bypass the PHP invoked gzip and decompress the file manually with gzip -d myxml.gz from the shell I get a complete valid xml file and re-run the php script it is happy to read the entire file into simplexml.

I get the same response when run via an Apache triggered event or manually via php-cli. I'm using Drupal 7, but don't think this should make any difference.

Any suggestions welcome.
 
I use this to grab and expand so might be able to reuse or crib bits:

Code:
<?php

class downloader {
    public $remote_file_url = '';
    public $local_filename = '';
    
    public function __construct() {
    }
    public function __destruct() {
    }
    
    public function setLocalFilename($filename) {
        $this->local_filename = $filename;
    }
    public function setRemoteFileURL($url) {
        $this->remote_file_url = $url;
    }
    
    public function doDownload() {
        if($this->remote_file_url!='') {
            /* Remove any previous download */
            if(file_exists($this->local_filename)) {
                exec("rm \"". $this->local_filename . "\"");
            }
            if(file_exists(str_replace('.gz','',$this->local_filename))) {
                exec("rm \"". str_replace('.gz','',$this->local_filename) . "\"");
            }
            /* Do download */
            exec('wget -q -O ' . $this->local_filename . ' ' . $this->remote_file_url);
            if(file_exists($this->local_filename)) {
                exec('gunzip ' . $this->local_filename);
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }
    
}

$downloader = new downloader;

$downloader->setRemoteFileURL('http://url.to.file.here');

$downloader->setLocalFilename('export_latest.xml.gz');
var_dump($downloader->doDownload());

?>
 
What's the curl code like? did you have something like:

curl_setopt($ch,CURLOPT_ENCODING , "gzip");

S
 
Status
Not open for further replies.

Rule #1: Be Respectful

Do not insult any other member. Be polite and do business. Thank you!

Members online

Premium Members

New Threads

Domain Forum Friends

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Siusaidh AcornBot:
    Siusaidh has left the room.
      Siusaidh AcornBot: Siusaidh has left the room.
      Top Bottom