You need to close the stream after writing to clear it before the data comes from reading.
list($in, $out) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $params = array('level' => 6, 'window' => 15, 'memory' => 9); stream_filter_append($out, 'zlib.deflate', STREAM_FILTER_WRITE, $params); stream_set_blocking($out, 0); stream_set_blocking($in, 0); fwrite($out, 'Some big long string.'); fclose($out); $compressed = fread($in, 1024); echo "Compressed:" . bin2hex($compressed) . "<br>\n"; list($in, $out) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $params = array('level' => 6, 'window' => 15, 'memory' => 9); stream_filter_append($out, 'zlib.deflate', STREAM_FILTER_WRITE, $params); stream_set_blocking($out, 0); stream_set_blocking($in, 0); fwrite($out, 'Some big long string, take two.'); fclose($out); $compressed = fread($in, 1024); echo "Compressed:" . bin2hex($compressed) . "<br>\n"; list($in, $out) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $params = array('level' => 6, 'window' => 15, 'memory' => 9); stream_filter_append($out, 'zlib.deflate', STREAM_FILTER_WRITE, $params); stream_set_blocking($out, 0); stream_set_blocking($in, 0); fwrite($out, 'Some big long string - third time is the charm?'); fclose($out); $compressed = fread($in, 1024); echo "Compressed:" . bin2hex($compressed) . "<br>\n";
This gives: Compressed: 789c0bcecf4d5548ca4c57c8c9cf4b57282e29cacc4bd70300532b079c Compressed: 789c0bcecf4d5548ca4c57c8c9cf4b57282e29cacc4bd7512849cc4e552829cfd70300b1b50b07 Compressed: 789c0bcecf4d5548ca4c57c8c9cf4b57282e29ca0452ba0a25199945290a259940c9cc62202f55213923b128d71e008e4c108c
I also switched $ in and $ out, because the entry in $ confused me.