reference appendices

Protocols And Wrappers

PHP stream wrappers let filesystem functions work with resources such as local files, standard streams, in-memory streams, and selected network protocols. Wrapper choice affects security and performance.

Use This Reference When

  • Using php://memory, php://temp, stdin, stdout, or stderr.
  • Reviewing file APIs that receive user-controlled paths.
  • Understanding why remote wrappers may need restriction.

Write To Memory

PHP example
<?php

$stream = fopen('php://memory', 'w+');
fwrite($stream, 'report');
rewind($stream);
echo stream_get_contents($stream) . PHP_EOL;
fclose($stream);

// Prints:
// report

Never pass an untrusted wrapper URI directly into file functions. Allow-list the intended storage scheme and path rules.

Practice

Use a Temporary Stream
Show solution

Temporary streams are useful when an API expects a stream but the application does not need a permanent file. They can reduce manual cleanup and memory pressure for larger data.