Example 1 — Toggle Blocking on a Memory Stream
Call stream_set_blocking() both ways and print whether each call succeeded.
<?php
$stream = fopen("php://memory", "r+");
$a = stream_set_blocking($stream, true);
$b = stream_set_blocking($stream, false);
echo "blocking on: ", $a ? "ok" : "fail", PHP_EOL;
echo "blocking off: ", $b ? "ok" : "fail", PHP_EOL;
fclose($stream); How It Works
- A memory stream is opened.
- stream_set_blocking($stream, true) turns blocking on.
- stream_set_blocking($stream, false) turns it off.
- Both calls return true in this tutorial, printed as ok.

