Membership is FREE, giving all registered users unlimited access to every Acorn Domains feature, resource, and tool! Optional membership upgrades unlock exclusive benefits like profile signatures with links, banner placements, appearances in the weekly newsletter, and much more - customized to your membership level!

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());

?>
 
Thanks, very odd, replaced my CURL code block with wget and it seems to work. I guess CURL must do something odd on the file download.
 
What's the curl code like? did you have something like:

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

S
 
I just set binary transfer and dumped to file.

The bit that stumped me was being able to unzip this manually using the same command :(

All seems to be working now.
 
Status
Not open for further replies.

The Rule #1

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.
      There are no messages in the current room.
      Top Bottom