Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing zlib filter with a socket pair
    text
    copied!<p>For some reason, the <code>zlib.deflate</code> filter doesn't seem to be working with socket pairs generated by <code>stream_socket_pair()</code>. All that can be read from the second socket is the two-byte zlib header, and everything after that is NULL.</p> <p>Example:</p> <pre><code>&lt;?php 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($in, 'zlib.deflate', STREAM_FILTER_WRITE, $params); stream_set_blocking($in, 0); stream_set_blocking($out, 0); fwrite($in, 'Some big long string.'); $compressed = fread($out, 1024); var_dump($compressed); fwrite($in, 'Some big long string, take two.'); $compressed = fread($out, 1024); var_dump($compressed); fwrite($in, 'Some big long string - third time is the charm?'); $compressed = fread($out, 1024); var_dump($compressed); </code></pre> <p>Output:</p> <pre><code>string(2) "x�" string(0) "" string(0) "" </code></pre> <p>If I comment out the call to <code>stream_filter_append()</code>, the stream writing/reading functions correctly, with the data being dumped in its entirety all three times, and if I direct the zlib filtered stream into a file instead of through the socket pair, the compressed data is written correctly. So both parts function correctly separately, but not together. Is this a PHP bug that I should report, or an error on my part?</p> <p><em>This question is branched from a solution to <a href="https://stackoverflow.com/questions/7207484/how-do-i-use-phps-stream-select-with-a-zlib-filter">this related question</a>.</em></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