23 Aug, 2011, Deimos wrote in the 1st comment:
Votes: 0
So… I'm writing a MUD in PHP and really want to implement MCCP, but can't figure out how to properly deflate output with the zlib extension. Right now I'm doing:

Server: IAC WILL COMPRESS2
Client: IAC DO COMPRESS2
Server: IAC SB COMPRESS2 IAC SE
Server: (compressed text using gzdeflate())

I'm testing with MushClient, and the negotiation succeeds, but when the first compressed text hits the client it disconnects complaining about a malformed compression stream.

Does anyone know if I might be missing something?
24 Aug, 2011, kiasyn wrote in the 2nd comment:
Votes: 0
make sure you are maintaining your gzip stream, not making a new gzip encoder every time you send data
25 Aug, 2011, Deimos wrote in the 3rd comment:
Votes: 0
I've also tried using stream_append_filter() with the zlib.deflate filter, which I think could solve the problem, but I don't know because filtered streams don't work with stream_select() so my polling stopped working.
25 Aug, 2011, Runter wrote in the 4th comment:
Votes: 0
I had the same problem. I believe it has to do with when the client expects compression to start exactly.
29 Aug, 2011, Deimos wrote in the 5th comment:
Votes: 0
I got it working in Ruby, but PHP is turning out to be a pain. Ruby is simply:

require "zlib"
foo = Zlib::Deflate.new()
bar = "test\r\n"
baz = foo.deflate(bar, Zlib::SYNC_FLUSH)


…after the subnegotiation noted in the OP.
17 Mar, 2012, Deimos wrote in the 6th comment:
Votes: 0
If anyone cares, I figured out how to do this in PHP. The core doesn't expose the flush flags required, meaning we can't flush on write (SYNC_FLUSH), but there is a PECL extension, pecl_http, which contains a class that allows us to to this, HttpDeflateStream:

<?php
$stream = new HttpDeflateStream(HttpDeflateStream::FLUSH_SYNC);
$compressedData = $stream->update($data);


Note that this extension requires that you have the zlib and zlib-devel packages installed (use yum, apt, or whatever).
0.0/6