Buy Sell Discuss UK Domain Names at AcornDomains.co.uk

Today's Drop Dates are: 19-02-2012 or 26-02-2012   All times are GMT. The time now is 12:43:53 PM.
Domain Name Sales Domain Software Calculate UK Domain Drop Dates Domain Registration NameDrive Domain Parking Subscribe to our Domains For Sale newsletter
Go Back   Domain Forum Acorn Domains Buy Sell Auction UK Domains > Website Design and Promotion > Website Design > Scripts and Coding
Connect with Facebook

Scripts and Coding PHP, MySQL, scripts

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 25-01-2011, 10:57:27 AM     #1 (permalink)

 
Join Date: May 2007
Posts: 1,148
monaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond repute

Is there a PHP / Gzip guru?

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.
__________________
Alex Monaghan - Drop Catch & Drop Lists - PM for details
Online Accounting|Pine Furniture|Barbie
monaghan is online now  
Old 25-01-2011, 11:00:52 AM     #2 (permalink)
rob
Founding Member
 
rob's Avatar
 
Join Date: Jan 2005
Posts: 5,978
rob has a reputation beyond reputerob has a reputation beyond reputerob has a reputation beyond reputerob has a reputation beyond reputerob has a reputation beyond reputerob has a reputation beyond reputerob has a reputation beyond reputerob has a reputation beyond reputerob has a reputation beyond reputerob has a reputation beyond reputerob has a reputation beyond repute

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

?>
rob is offline  
Old 25-01-2011, 11:26:35 AM     #3 (permalink)

 
Join Date: May 2007
Posts: 1,148
monaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond repute

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.
__________________
Alex Monaghan - Drop Catch & Drop Lists - PM for details
Online Accounting|Pine Furniture|Barbie
monaghan is online now  
Old 25-01-2011, 11:38:20 AM     #4 (permalink)

 
tifosi's Avatar
 
Join Date: Oct 2004
Location: Lancashire
Posts: 1,907
tifosi has a reputation beyond reputetifosi has a reputation beyond reputetifosi has a reputation beyond reputetifosi has a reputation beyond reputetifosi has a reputation beyond reputetifosi has a reputation beyond reputetifosi has a reputation beyond reputetifosi has a reputation beyond reputetifosi has a reputation beyond reputetifosi has a reputation beyond reputetifosi has a reputation beyond repute

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

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

S
tifosi is offline  
Old 25-01-2011, 11:45:21 AM     #5 (permalink)

 
Join Date: May 2007
Posts: 1,148
monaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond repute

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.
__________________
Alex Monaghan - Drop Catch & Drop Lists - PM for details
Online Accounting|Pine Furniture|Barbie
monaghan is online now  
Closed Thread



Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Domain Name Community Replies Last Post
Experienced freelance developer available (PHP, MySQL, Wordpress, feeds, APIs, etc. MartinWood Scripts and Coding 0 06-09-2010 11:33:05 AM
Which PHP framework monaghan Scripts and Coding 6 22-07-2010 08:31:56 PM
PHP include in a Smarty Template admin Scripts and Coding 1 13-05-2008 06:37:26 AM

Web Hosting from UK2 from just 99p


All times are GMT. The time now is 12:43:53 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0 RC 2
All content on Acorn Domains is member generated and is not moderated before posting. All content is viewed and used by you at your own risk and AD does not warrant the accuracy or reliability of any of the information. The views expressed are those of the individual contributors and not necessarily those of AD. Please contact us to report any issues or send a PM to "Admin".