You can use a channel and add a filter to the channel instead.
This will allow you to use stream_select in the stream, and the channel will serve as a buffer for zlib.
Read the raw data from the select () ed stream, write it in the pipe and read the decoded data from the other side :)
list($in, $out) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0); stream_filter_append($out, 'zlib.inflate', STREAM_FILTER_READ); stream_set_blocking($out, 0); while (stream_select(...)) { // assuming that $stream is non blocking stream_copy_to_stream($stream, $in); $decoded_data = stream_get_contents($out); }
The same can be achieved using php: // memory stream.
source share