![]() |
| Domain Name Sales | Domain Software | Calculate UK Domain Drop Dates | Domain Registration | NameDrive | Domain Parking | Subscribe to our Domains For Sale newsletter |
| | ||||||
| Home | Register | Rules | Membership Upgrade | Domains For Sale | Domain Name Escrow | Mark Forums Read | Domain Classified | Chat Room |
| Scripts and Coding PHP, MySQL, scripts |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
![]() | 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 |
| |
| | #2 (permalink) |
| Founding Member |
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());
?> |
| |
| | #3 (permalink) |
![]() |
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 |
| |
| | #4 (permalink) |
![]() |
What's the curl code like? did you have something like: curl_setopt($ch,CURLOPT_ENCODING , "gzip"); S |
| |
| | #5 (permalink) |
![]() |
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 |
| |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
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 |