Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to close the stream after the write to flush it before the data will come in from the read. </p> <pre><code>list($in, $out) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $params = array('level' =&gt; 6, 'window' =&gt; 15, 'memory' =&gt; 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) . "&lt;br&gt;\n"; list($in, $out) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $params = array('level' =&gt; 6, 'window' =&gt; 15, 'memory' =&gt; 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) . "&lt;br&gt;\n"; list($in, $out) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $params = array('level' =&gt; 6, 'window' =&gt; 15, 'memory' =&gt; 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) . "&lt;br&gt;\n"; </code></pre> <p>That produces: Compressed:789c0bcecf4d5548ca4c57c8c9cf4b57282e29cacc4bd70300532b079c Compressed:789c0bcecf4d5548ca4c57c8c9cf4b57282e29cacc4bd7512849cc4e552829cfd70300b1b50b07 Compressed:789c0bcecf4d5548ca4c57c8c9cf4b57282e29ca0452ba0a25199945290a259940c9cc62202f55213923b128d71e008e4c108c</p> <p>Also I switched the $in and $out because writing to $in confused me.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload