Example 1 — Read a Memory Stream
Write text into php://memory, rewind, then read everything with stream_get_contents().
<?php
$stream = fopen("php://memory", "r+");
fwrite($stream, "hello stream");
rewind($stream);
echo stream_get_contents($stream), PHP_EOL;
fclose($stream); How It Works
- fopen() opens an in-memory stream for reading and writing.
- fwrite() stores the text and leaves the pointer at the end.
- rewind() moves back to the start so the next read sees the data.
- stream_get_contents() returns the full string "hello stream".

