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. Share your own thoughts and experience, accounts may be terminated for violations.
  • Welcome to AcornDomains.co.uk, a friendly community for UK domain investors, developers and anyone interested in domain names.

    Whether you're looking to buy or sell domains, learn more about the UK domain market, get feedback on your names, or simply chat with other domainers, you're in the right place. AcornDomains has been bringing together people from across the UK domain industry for many years, from complete beginners to experienced investors.

    Have a look around, join the discussions and, if you haven't already, create a free account and introduce yourself.

Is there a PHP / Gzip guru?

Status
Not open for further replies.
Joined
May 31, 2007
Posts
2,090
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.
Top Bottom