Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3304136
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:01:49+00:00 2026-05-17T21:01:49+00:00

I’m working on a project where a Windows web server running PHP is communicating

  • 0

I’m working on a project where a Windows web server running PHP is communicating over a very slow connection with a back end Linux server running an application written in C++. Because the connection between the two machines is so slow, I’d like to compress the traffic moving between them.

I’ve gotten to where I can compress a string, save it to a file, read the file, and uncompress the string in C++ using Zlib, and likewise in PHP. However, if I try to compress a string in one language and decompress it in the other (as will be happening in the real world), I get errors griping that the compressed data is corrupted. I’ve also noticed that the same string compressed in C++ results in a different file than in PHP, which leads me to believe that Zlib is using a different compression algorithm on each language.

I’m using default settings on both sides. The C++ I’m using to do the compression and decompression is

compress((Bytef*)compressed, (uLongf*)&compressedLength, (Bytef*)uncompressed, (uLong)uncomressedLength);
uncompress((Bytef*)uncompressed, (uLongf*)&uncomressedLength, (Bytef*)compressed, (uLong)compressedLength);

while the PHP code is

$compressed = gzcompress($uncompressed);
$uncompressed = gzuncompress($compressed);

Why are these resulting in different compressed strings? Is that what’s causing the problems with decompression? What should I be doing to get this to work? Also, I’m not committed to Zlib. Zlib’s what my initial research uncovered, but if there’s a better way to do this, I’m all ears.

Edit: Actually, after doing a little more testing, it appears that C++ was working with my initial test case, but not universally. I tried it with the input “hellohellohello”, and on decompression, it reported a Z_DATA_ERROR and decompressed it to just “hello”. I guess that means I’m doing something wrong on the C++ side, which may explain why PHP is unhappy decompressing C++ compressed strings.

Edit 2: I tried out the zpipe.c sample program, and it correctly uncompresses strings compressed by PHP and produces compressed strings PHP can uncompress. Clearly, the problem(s) exist in my C++ code. Either my usage of compress and uncompress is incorrect, or I’m reading and writing the file incorrectly. Neither the compress or decompress programs interact correctly with zpipe.

Update: I’ve now gotten to where I can compress a string using PHP and read it with either PHP or C++, and I can compress a string with C++ and read it with C++, but attempting to read it with PHP results in PHP Warning: gzuncompress(): data error. What could be different that would cause this combination of working/not working scenarios?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:01:49+00:00Added an answer on May 17, 2026 at 9:01 pm

    Zlib’s default compression level is 6 – you could try passing that as the second param on gzcompress for PHP.

    string gzcompress ( string $data [, int $level = -1 ] )
    

    From the ZLIB manual:

    The compression level must be
    Z_DEFAULT_COMPRESSION, or between 0
    and 9: 1 gives best speed, 9 gives
    best compression, 0 gives no
    compression at all (the input data is
    simply copied a block at a time).
    Z_DEFAULT_COMPRESSION requests a
    default compromise between speed and
    compression (currently equivalent to
    level 6)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.