Jump to content

gzuncompress() behaves differently on 2 server.


Go to solution Solved by sftd,

Recommended Posts

I have the following problem:

 

For various reasons I have 30 chunks of data that I'm using gzuncompress() on and have 2 servers:

Linux, PHP 5.3.29, zlib 1.2.3

Windows, PHP 5.5.8, zlib 1.2.7.3

 

- 28 chunks are uncompressed correctly on both servers.

- 1 chunk throws error on both servers (but it's expected).

- 1 chunk throws error ONLY on Linux server.

 

Can anyone suggest what might be the cause of this and suggest fix that won't require upgrading PHP on Linux server?

 

 

Thank you for your help.

Edited by sftd

Thank you for your interest.

 

Here is the "core" of the problem. I separated the chunk of data that I have problem with. Not much code needed to recreate the error difference.

`gz-test.txt` in attachment.

$var = file_get_contents('./gz-test.txt');

echo gzuncompress($var);

- Windows server just outputs uncompressed data.

- Linux server throws out the following Warning (data-error): `Warning: gzuncompress(): data error in C:\SfTd\Programming\Projects\PHP\PHKonrad Kojarzenia\www\gz-test.php on line 8`

gz-test.txt

Edited by sftd

It's a part of PDF file I'm parsing.

 

To clarify. My main question here is "does `gzuncompress` give different results because of "OS difference", "PHP version difference", "some other reason" or "impossible to tell".

Edited by sftd

It shouldn't, but it might behave differently between versions.

 

gzuncompress is for Zlib. You probably want gzdecode instead.

 

EDIT: But either way the file you attached doesn't seem to be valid. The Linux gzip tools cannot view it either.

Edited by scootstah
  • Solution

So after a lot of comparing and testing turned out that for some reason `gzuncompress()` version on Linux server needs in this particular data chunk an extra 0 byte at the end (which doesn't bother "correct" chunks, so my solution was to just add 0 byte at the end, to every data chunk).

 

Though probably the best solution would be to upgrade to newer zlib.

Edited by sftd
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.