sftd Posted September 29, 2015 Share Posted September 29, 2015 (edited) 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 September 29, 2015 by sftd Quote Link to comment https://forums.phpfreaks.com/topic/298367-gzuncompress-behaves-differently-on-2-server/ Share on other sites More sharing options...
scootstah Posted September 29, 2015 Share Posted September 29, 2015 It would help if you post code and the error you're getting. Quote Link to comment https://forums.phpfreaks.com/topic/298367-gzuncompress-behaves-differently-on-2-server/#findComment-1521895 Share on other sites More sharing options...
sftd Posted September 29, 2015 Author Share Posted September 29, 2015 (edited) 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 September 29, 2015 by sftd Quote Link to comment https://forums.phpfreaks.com/topic/298367-gzuncompress-behaves-differently-on-2-server/#findComment-1521902 Share on other sites More sharing options...
scootstah Posted September 29, 2015 Share Posted September 29, 2015 The file you attached is not a valid gzip file. How did you create it? Quote Link to comment https://forums.phpfreaks.com/topic/298367-gzuncompress-behaves-differently-on-2-server/#findComment-1521903 Share on other sites More sharing options...
sftd Posted September 29, 2015 Author Share Posted September 29, 2015 (edited) 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 September 29, 2015 by sftd Quote Link to comment https://forums.phpfreaks.com/topic/298367-gzuncompress-behaves-differently-on-2-server/#findComment-1521905 Share on other sites More sharing options...
scootstah Posted September 29, 2015 Share Posted September 29, 2015 (edited) 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 September 29, 2015 by scootstah Quote Link to comment https://forums.phpfreaks.com/topic/298367-gzuncompress-behaves-differently-on-2-server/#findComment-1521907 Share on other sites More sharing options...
sftd Posted September 29, 2015 Author Share Posted September 29, 2015 (edited) I was experimenting with `gzdecode` but in my case it wasn't the solution. Anyway thank you for your help. Edited September 29, 2015 by sftd Quote Link to comment https://forums.phpfreaks.com/topic/298367-gzuncompress-behaves-differently-on-2-server/#findComment-1521909 Share on other sites More sharing options...
Solution sftd Posted September 29, 2015 Author Solution Share Posted September 29, 2015 (edited) 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 September 29, 2015 by sftd Quote Link to comment https://forums.phpfreaks.com/topic/298367-gzuncompress-behaves-differently-on-2-server/#findComment-1521918 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.